php with special characters like ñ

后端 未结 6 644
傲寒
傲寒 2021-02-06 09:50

At first I thought the problem was when I return echo json_encode($row) from an ajax call that results with ñ are changed to NULL. But after testing I found out that the problem

相关标签:
6条回答
  • 2021-02-06 10:26

    for me

    $test = "Nuñez";
    echo $test;
    

    shows Nuñez

    You may try

    $test = "Nuñez";
    echo utf8_decode($test);
    

    or

    $test = utf8_encode("Nuñez");
    echo utf8_decode($test);
    
    0 讨论(0)
  • 2021-02-06 10:27

    to show correctly latin characters like ñ Ñ á é í ó ú, etc.. in browsers, you have to use iso-8859-1 instead of UTF-8 encoding http://www.w3schools.com/tags/ref_entities.asp

    best regards!

    0 讨论(0)
  • 2021-02-06 10:31

    Face the same issue with the string "CASTAÑO".

    I've tried posted solutions.

    I used the ini_set('default_charset', 'utf-8'); directive.

    • The selected record showed "CASTA�O"
    • Using utf8-decode showed "CASTA?O"
    • Using utf8_encode shows the proper string "CASTAÑO"
    0 讨论(0)
  • 2021-02-06 10:33

    when you connect to your mysql db, set charset to utf-8, like ->

    $sql_con = mysql_connect($sql_host, $sql_user, $sql_pass);
    mysql_query('SET NAMES utf8');
    
    0 讨论(0)
  • 2021-02-06 10:34

    Try this

    Its works for me.

    $test = "Nuñez";
    
    echo html_entity_decode(htmlentities($test));
    
    0 讨论(0)
  • 2021-02-06 10:49

    consider setting default_charset, this worked for me

    ini_set('default_charset', 'utf-8');

    0 讨论(0)
提交回复
热议问题