PHP code example of eru / avro-phonetic

1. Go to this page and download the library: Download eru/avro-phonetic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eru / avro-phonetic example snippets


Avro::to('rri');   // ঋ (at word start)
Avro::to('krri');  // কৃ (after consonant)

Avro::to('OI');    // ঐ (standalone)
Avro::to('kOI');   // কৈ (after consonant)

use Eru\AvroPhonetic\Avro;

// Static method
echo Avro::to('ami banglay gan gai');
// Output: আমি বাংলায় গান গাই

// Instance method
$avro = new Avro();
echo $avro->parse('amar sonar bangla');
// Output: আমার সনার বাংলা

// Quick conversion
echo avro('bangladesh');  // বাংলাদেশ
echo bangla('dhaka');     // ঢাকা

// Get instance for chaining
$result = avro()->parse('tumi kemon acho');

use Eru\AvroPhonetic\Facades\Avro;

// In your controller
public function store(Request $request)
{
    $bengaliText = Avro::to($request->input('text'));
    // ...
}

use Eru\AvroPhonetic\Avro;

// Static conversion
Avro::to(string $text): string

// Instance methods
$avro = new Avro();
$avro->parse(string $text): string
$avro->convert(string $text): string  // Alias for parse()

// Factory methods
Avro::getInstance(): Avro                        // Singleton
Avro::withGrammar(array $grammar): Avro          // Custom grammar
Avro::fromGrammarFile(string $path): Avro        // Load from file

// Access parser
$avro->getParser(): PhoneticParser

// Convert text or get instance
avro(?string $text = null): Avro|string

// Always converts text
bangla(string $text): string

$customGrammar = [
    'patterns' => [
        ['find' => 'ph', 'replace' => 'ফ', 'rules' => []],
        // ... more patterns
    ],
    'vowel' => 'aeiou',
    'consonant' => 'bcdfghjklmnpqrstvwxyz',
    'number' => '1234567890',
    'casesensitive' => 'oiudgjnrstyz',
];

$avro = Avro::withGrammar($customGrammar);
echo $avro->parse('phone'); // ফনে

$avro = Avro::fromGrammarFile('/path/to/custom-grammar.json');

use Eru\AvroPhonetic\PhoneticParser;

$grammar = json_decode(file_get_contents('grammar.json'), true);
$parser = new PhoneticParser($grammar);

// Parse multiple texts
foreach ($texts as $text) {
    $results[] = $parser->parse($text);
}
bash
php artisan vendor:publish --tag=avro-phonetic-config