PHP code example of zvermafia / transliteration

1. Go to this page and download the library: Download zvermafia/transliteration 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/ */

    

zvermafia / transliteration example snippets




namespace Whatever\Namespace;

use Zvermafia\Transliteration\Interfaces\TransliteratorInterface;

// point #1
class MyTransliterator implements TransliteratorInterface
{
    // realize all the methods defined in the interface (
}



namespace Whatever\Namespace;

use Zvermafia\Transliteration\Abstracts\TransliteratorAbstract;
use Zvermafia\Transliteration\Interfaces\TransliteratorInterface;

// point #1
class MyTransliterator extends TransliteratorAbstract
{
    public function translit(): : TransliteratorInterface
    {
        $text = $this->getText();
        // $result = ... // here translit the text
        $this->setResult($result);

        return $this;
    }
}
 php
 Initialize the object
$transliterator = new Zvermafia\Transliteration\AlifTransliterator(); // or you can use LotinTransliterator

$transliterator->setText("Salom, dunyo!")
    ->toCyrillic()
    ->translit();

echo $transliterator->getResult(); // it will output: Салом, дунё!