在开发我的一个网站时,我注意到,如果我输入阿拉伯数字(١٢٣),它们不被解释为实数值。然后,我测试了其他几个网站,结果发现它们也不接受阿拉伯数字。
问题是,我的客户似乎需要这个功能(接受阿拉伯数字)..我不知道该从何说起我的平台是magento (php)
您需要在./mage install
中安装阿拉伯语包-请参阅http://www.magentocommerce.com/magento-connect/Ahmed+J.+Hadi/extension/353/magento-community-modules--arabic-saudi-arabia-language-pack
允许PHP接受阿拉伯数字或波斯数字(波斯语)(١٢٣٤٥),我开发了这个简单的函数:
<?php
/*
/////////////////////
This function has been created by Abdulfattah alhazmi
Roles:
To convert Arabic/Farsi Numbers (٠ - ١ - ٢ - ٣ - ٤ - ٥ - ٦ - ٧ - ٨ - ٩)
TO the corrosponding English numbers (0-1-2-3-4-5-6-7-8-9)
http://hazmi.co.cc
/////////////////////
*/
function convertArabicNumbers($arabic) {
$trans = array(
"٠" => "0",
"١" => "1",
"٢" => "2",
"٣" => "3",
"٤" => "4",
"٥" => "5",
"٦" => "6",
"٧" => "7",
"٨" => "8",
"٩" => "9",
);
return strtr($arabic, $trans);
}
?>
注意:要从表单中的文本字段中获得正确的结果,您必须使用htmlspecialchars_decode()
函数。例如:
$mytext = htmlspecialchars_decode($_POST['mytext']));
$mytext = convertArabicNumbers($mytext);
为了保证代码的安全,添加strip_tags()
。例如:
$mytext = strip_tags(htmlspecialchars_decode($_POST['mytext']));
$mytext = convertArabicNumbers($mytext);
奇怪的是,Abdulfattah Alhazmi函数没有与我一起工作,经过了很多尝试&错误,下面的操作对我有效。
function convertArabicNumbers($arabic) {
$trans = array(
"٠" => "0",
"١" => "1",
"٢" => "2",
"٣" => "3",
"٤" => "4",
"٥" => "5",
"٦" => "6",
"٧" => "7",
"٨" => "8",
"٩" => "9",
);
return strtr($arabic, $trans);
}
实际上,阿拉伯数字与波斯语数字并不完全相同。例如,(波斯语中的4和5)和(阿拉伯语中的4和5)不同。我认为(6)也是不一样的。所以需要使用Unicode来表示实际的"波斯语"如果他们想要得到正确的波斯语数字