为什么阿拉伯数字(123)在文本框中不被接受为实数?

mah*_*aha 15 php numbers arabic magento

在开发我的一个网站时,我注意到如果我输入阿拉伯数字(123),它们不会被解释为实数值.然后,我测试了一些其他网站,却发现他们也不接受阿拉伯数字.

问题是,我的客户似乎需要这个功能(接受阿拉伯数字)..我不知道从哪里开始.我的平台是magento(php).

Abd*_*zmi 4

为了让 PHP 接受阿拉伯数字或波斯数字(波斯语)(\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xa4\xd9\xa5),\n我开发了这个简单的函数:

\n\n
<?php\n\n/*\n/////////////////////\nThis function has been created by Abdulfattah alhazmi\nRoles:\nTo convert Arabic/Farsi Numbers (\xd9\xa0\xe2\x80\x8e - \xd9\xa1\xe2\x80\x8e - \xd9\xa2\xe2\x80\x8e - \xd9\xa3\xe2\x80\x8e - \xd9\xa4\xe2\x80\x8e - \xd9\xa5\xe2\x80\x8e - \xd9\xa6\xe2\x80\x8e - \xd9\xa7\xe2\x80\x8e - \xd9\xa8\xe2\x80\x8e - \xd9\xa9\xe2\x80\x8e) \nTO the corrosponding English numbers (0-1-2-3-4-5-6-7-8-9)\nhttp://hazmi.co.cc\n/////////////////////\n*/\n\nfunction convertArabicNumbers($arabic) {\n    $trans = array(\n        "&#1632;" => "0",\n        "&#1633;" => "1",\n        "&#1634;" => "2",\n        "&#1635;" => "3",\n        "&#1636;" => "4",\n        "&#1637;" => "5",\n        "&#1638;" => "6",\n        "&#1639;" => "7",\n        "&#1640;" => "8",\n        "&#1641;" => "9",\n    );\n    return strtr($arabic, $trans);\n}\n?>\n
Run Code Online (Sandbox Code Playgroud)\n\n

注意:要从表单中的文本字段获取正确的结果,您必须使用该htmlspecialchars_decode()函数。例如:

\n\n
$mytext = htmlspecialchars_decode($_POST[\'mytext\']));\n$mytext = convertArabicNumbers($mytext);\n
Run Code Online (Sandbox Code Playgroud)\n\n

为了保证您的代码安全,请添加strip_tags(). 例如:

\n\n
$mytext = strip_tags(htmlspecialchars_decode($_POST[\'mytext\']));\n$mytext = convertArabicNumbers($mytext);\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果您对此功能还有任何疑问,请随时询问我。

\n