utf-8 special characters not displaying

前端 未结 8 1330
暗喜
暗喜 2020-12-03 06:47

I moved my website from my local test server to NameCheap shared hosting and now I\'m running into a problem - some of the pages aren\'t displaying utf-8 special characters

相关标签:
8条回答
  • 2020-12-03 07:27

    This is really annoying problem to fix but you can try these.

    First of all, make sure the file is actually saved in UTF-8 format.

    Then check that you have <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> in your HTML header.

    You can also try calling header('Content-Type: text/html; charset=utf-8'); at the beginning of your PHP script or adding AddDefaultCharset UTF-8 to your .htaccess file.

    0 讨论(0)
  • 2020-12-03 07:36

    I solve my issue by using utf8_encode();

    $str = "kamé";

    echo utf8_encode($str);

    Hope this help someone.

    0 讨论(0)
  • 2020-12-03 07:36

    If all the other answers didn't work for you, try disabling HTTP input encoding translation.

    This is a setting related to PHP extension mbstring. This was the problem in my case. This setting was enabled by default in my server.

    0 讨论(0)
  • 2020-12-03 07:39

    The problem is because your file are not with the same encoding. First run the following command in all your files:

    file -i filename.* 
    

    In order to fix the problem you have to change all your files to uft-8. You can do it with the command iconv:

    iconv -f fromcode -t tocode filename > newfilename
    

    Example:

    iconv -f iso-8859-1 -t utf-8 index.html > fixed/index.html
    

    After this you can run file -i fixedx/index.html and you will see that your file is now in uft-8

    0 讨论(0)
  • 2020-12-03 07:47

    If you're using PHP and none of the above worked (as it was my case), you need to set the locale with utf-8 encoding.

    Like this

    setlocale(LC_ALL, 'fr_CA.utf-8');
    
    0 讨论(0)
  • 2020-12-03 07:49

    set meta tag in head as

     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
    

    use the link http://www.i18nqa.com/debug/utf8-debug.html to replace the symbols character you want.

    then use str_replace like

        $find = array('“', '’', '…', '—', '–', '‘', 'é', 'Â', '•', 'Ëœ', 'â€'); // en dash
                            $replace = array('“', '’', '…', '—', '–', '‘', 'é', '', '•', '˜', '”');
    $content = str_replace($find, $replace, $content);
    

    Its the method i use and help alot. Thanks!

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