为什么文本框中不接受阿拉伯数字 (١٢٣) 作为实数? [英] why are arabic numbers (١٢٣) not accepted in textboxes as real numbers?
问题描述
在开发我的一个网站时,我注意到如果我输入阿拉伯数字 (١٢٣),它们不会被解释为实数值.然后,我测试了其他一些网站,却发现它们也不接受阿拉伯数字.
while developing one of my sites, i noticed that if I enter arabic numbers (١٢٣), they are not interpreted as real number values. Then, I tested a few other sites only to find that they also don't accept arabic numbers.
问题是,我的客户似乎需要这个功能(接受阿拉伯数字).我不知道从哪里开始.我的平台是 magento (php).
The problem is, my client seems to require this functionality (accepting arabic numbers).. and I have no idea where to start. My platform is magento (php).
推荐答案
允许 PHP 接受阿拉伯数字或波斯数字(波斯语)(١٢٣٤٥),我开发了这个简单的功能:
To allow PHP to accept the Arabic numbers or Persian numbers (Farsi) (١٢٣٤٥), I developed this easy function:
<?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()
函数.例如:
Note: TO GET THE CORRECT RESULT from text field in your form, you have to use the htmlspecialchars_decode()
function. For example:
$mytext = htmlspecialchars_decode($_POST['mytext']));
$mytext = convertArabicNumbers($mytext);
为了确保您的代码安全,请添加 strip_tags()
.例如:
To keep your code safe, add strip_tags()
. For example:
$mytext = strip_tags(htmlspecialchars_decode($_POST['mytext']));
$mytext = convertArabicNumbers($mytext);
如果您对此功能还有任何疑问,请随时问我.
Please don't hesitate to ask me if you have any further question about this function.
这篇关于为什么文本框中不接受阿拉伯数字 (١٢٣) 作为实数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!