Zend_Locale_Format::convertNumerals() converts digits between
different numeral
systems, including the standard Arabic/European/Latin numeral system
(0,1,2,3,4,5,6,7,8,9), not to be confused with Eastern Arabic
numerals sometimes used with the Arabic language to express numerals.
Attempts to use an unsupported numeral system will result in an exception, to avoid
accidentally performing an incorrect conversion due to a spelling error. All characters
in the input, which are not numerals for the selected numeral system, are copied to the
output with no conversion provided for unit separator characters.
Zend_Locale* components rely on the data provided by
CLDR (see their list
of scripts grouped by language).
In CLDR and hereafter, the Europena/Latin numerals will be referred to as "Latin" or by the assigned 4-letter code "Latn". Also, the CLDR refers to this numeral systems as "scripts".
Suppose a web form collected a numeric input expressed using Eastern Arabic digits
"١٠٠". Most software and PHP functions expect input using Arabic
numerals. Fortunately, converting this input to its equivalent Latin numerals "100"
requires little effort using convertNumerals($inputNumeralString,
$sourceNumeralSystem, $destNumeralSystem), which returns the
$input with numerals in the script
$sourceNumeralSystem converted to the script
$destNumeralSystem.
Example 560. Converting numerals from Eastern Arabic scripts to European/Latin scripts
<?php
$arabicScript = "١٠٠"; // Arabic for "100" (one hundred)
$latinScript = Zend_Locale_Format::convertNumerals($arabicScript,
'Arab',
'Latn');
print "\nOriginal: " . $arabicScript;
print "\nNormalized: " . $latinScript;
Similarly, any of the supported numeral systems may be converted to any other supported numeral system.
Example 561. Converting numerals from Latin script to Eastern Arabic script
<?php
$latinScript = '123';
$arabicScript = Zend_Locale_Format::convertNumerals($latinScript,
'Latn',
'Arab');
print "\nOriginal: " . $latinScript;
print "\nLocalized: " . $arabicScript;
Example 562. Getting 4 letter CLDR script code using a native-language name of the script
<?php
function getScriptCode($scriptName, $locale)
{
$scripts2names = Zend_Locale_Data::getList($locale, 'script');
$names2scripts = array_flip($scripts2names);
return $names2scripts[$scriptName];
}
echo getScriptCode('Latin', 'en'); // outputs "Latn"
echo getScriptCode('Tamil', 'en'); // outputs "Taml"
echo getScriptCode('tamoul', 'fr'); // outputs "Taml"
For a list of supported numeral systems call
Zend_Locale::getTranslationList('numberingsystem', 'en').




