why are arabic numbers (١٢٣) not accepted in textboxes as real numbers?

谁说胖子不能爱 提交于 2019-11-30 01:48:29

问题


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.

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).


回答1:


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(
        "&#1632;" => "0",
        "&#1633;" => "1",
        "&#1634;" => "2",
        "&#1635;" => "3",
        "&#1636;" => "4",
        "&#1637;" => "5",
        "&#1638;" => "6",
        "&#1639;" => "7",
        "&#1640;" => "8",
        "&#1641;" => "9",
    );
    return strtr($arabic, $trans);
}
?>

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);

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.




回答2:


AFAIK you need to install an arabic language pack with ./mage install - see http://www.magentocommerce.com/magento-connect/Ahmed+J.+Hadi/extension/353/magento-community-modules--arabic-saudi-arabia-language-pack




回答3:


Strangely Abdulfattah Alhazmi function didn't worked with me, after lot of try & error, the below worked with me.

function convertArabicNumbers($arabic) {
    $trans = array(
        "٠" => "0",
        "١" => "1",
        "٢" => "2",
        "٣" => "3",
        "٤" => "4",
        "٥" => "5",
        "٦" => "6",
        "٧" => "7",
        "٨" => "8",
        "٩" => "9",
    );
    return strtr($arabic, $trans);
}


来源:https://stackoverflow.com/questions/8132997/why-are-arabic-numbers-%d9%a1%d9%a2%d9%a3-not-accepted-in-textboxes-as-real-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!