PHP code example of omar-haris / arabic-name-transliterator
1. Go to this page and download the library: Download omar-haris/arabic-name-transliterator 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/ */
omar-haris / arabic-name-transliterator example snippets
use ArabicNameTransliterator\Transliterator;
use ArabicNameTransliterator\Mapping\IraqMapping;
// Create a transliterator with Iraqi name mapping
$transliterator = new Transliterator(new IraqMapping());
// Transliterate names
echo $transliterator->transliterate('محمد'); // "Muhammad"
echo $transliterator->transliterate('عبد الرحمن'); // "Abd Al-Rahman"
echo $transliterator->transliterate('فاطمة الزهراء'); // "Fatimah Al-Zahraa"
// Works with diacritics
echo $transliterator->transliterate('مُحَمَّد'); // "Muhammad"
// Disable capitalization
echo $transliterator->transliterate('محمد علي', false); // "muhammad ali"
use ArabicNameTransliterator\Mapping\BaseMapping;
class EgyptianMapping extends BaseMapping
{
public function getFullWordMap(): array
{
return [
'محمد' => 'Mohamed', // Egyptian spelling (vs. Iraqi "Muhammad")
'عبد الرحمن' => 'Abdelrahman', // Different format
// Add more mappings...
];
}
public function getLetterMap(): array
{
return [
'ج' => 'g', // In Egyptian dialect, ج is pronounced as "g" not "j"
// Define the rest of your letter map...
];
}
}
$egyptianTransliterator = new Transliterator(new EgyptianMapping());
use ArabicNameTransliterator\Mapping\IraqMapping;
class CustomIraqMapping extends IraqMapping
{
public function getFullWordMap(): array
{
$originalMap = parent::getFullWordMap();
// Add or override specific entries
$customEntries = [
'محمد' => 'Mohammed', // Override the default 'Muhammad'
'عبد العزيز' => 'Abdul Aziz', // New entry
];
return array_merge($originalMap, $customEntries);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.