PHP print() Arabic string

后端 未结 5 1675
无人共我
无人共我 2021-01-20 05:32

When I try and execute this code to print out an Arabic string: print(\"إضافة\"); I get this output: إضاÙØ©. If I utf8_decode() it I\'ll get <

相关标签:
5条回答
  • 2021-01-20 05:39

    Well,

    First: Add by the beginning of HTML page

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    

    second: if you are using AJAX encode data using encodeURIComponent

    Third: First line of your PHP page should be

    header('Content-Type: text/html; charset=utf-8'); 
    

    and decode the data sent to PHP using urldecode

    Regards,

    0 讨论(0)
  • 2021-01-20 05:43

    It might be necessary to indicate to the browser which charset you are using -- I'm guessing it's UTF-8.

    IN order to achive that, you might try putting this portion of code at the beginning of your script, before any output is generated :

    header('Content-type: text/html; charset=UTF-8');
    


    [utf8_decode][1] will try to decode your string from UTF-8 to latin1, which is not suited for Arabic characters -- hence the '?' characters.

    0 讨论(0)
  • 2021-01-20 05:57

    Also set your page language to utf8 eg:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    

    and then see it if worked. If that still doesn't work, go and check this out, it is complete solution for the arabic language using PHP:

    http://www.ar-php.org/en_index_php_arabic.html

    You may want to check out this too:

    http://www.phpclasses.org/browse/package/2875.html

    0 讨论(0)
  • 2021-01-20 05:57

    You may also want to check your browser font if it has Arabic support. Stick to common fonts like Arial Unicode and Times New Roman.

    0 讨论(0)
  • 2021-01-20 05:59

    You may want to set

    default_charset = "utf-8"
    

    in your php.ini. Default charset directive instructs the server to produce correct content type header.

    You can also do it in runtime:

    ini_set('default_charset', 'utf-8');
    
    0 讨论(0)
提交回复
热议问题