Spanish Characters not Displaying Correctly

后端 未结 7 1976
心在旅途
心在旅途 2021-02-08 12:24

I am getting the lovely � box where spanish characters should be displayed. (ie: ñ, á, etc). I have already made sure that my meta http-equiv is set to utf-8:

&         


        
相关标签:
7条回答
  • 2021-02-08 12:53

    Use utf8mb4 or Windows-1252

    ini_set('default_charset', 'utf8mb4');
    

    or

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

    then use tag,

    <meta charset="utf8mb4">
    
    0 讨论(0)
  • 2021-02-08 13:02

    Can you see that the content is correct in the database table, look at it with phpmyadmin for eg. If it is, be sure your php files are utf8 encoded, take a look at your ide/editor configuration.

    0 讨论(0)
  • 2021-02-08 13:06

    it's important to check that your code is also codified as UTF-8 (you can see this property in a lot of text and code editors).

    Because there is only one symbol (the black square), its probably that you are using ISO-8859-1 or ISO-8859-15 .

    0 讨论(0)
  • 2021-02-08 13:10

    Things to consider in PHP/MySQL/UTF-8

    • The database tables and text columns should be set to UTF-8
    • HTML page Content-Type should be set to UTF-8

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

    • PHP should send a header informing the browser to expect UTF-8

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

    • The PHP-MySQL connection should be set to UTF-8

      mysqli_query("SET CHARACTER_SET_CLIENT='utf8'",$conn);

      mysqli_query("SET CHARACTER_SET_RESULTS='utf8'",$conn);

      mysqli_query("SET CHARACTER_SET_CONNECTION='utf8'",$conn);

    • PHP ini has default_charset setting it should be utf-8 if you do not have access to it use ini_set('default_charset', 'utf-8');

    0 讨论(0)
  • 2021-02-08 13:12

    Having a similar problem, I found the answer here. Not Displaying Spanish Characters

    The resolution was to change from UTF-8 to windows-1252.

    (HTML) <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
    (PHP) ini_set('default_charset', 'windows-1252');
    

    My problem was reading Spanish characters from a CSV file. When I opened the file in Excel, the characters appeared fine. In my editor, the odd character was shown regardless of the intended character. This change seems to work for my requirements.

    0 讨论(0)
  • 2021-02-08 13:14

    I have suffered this problem for many years and I can't find any logic and I have tried all the solutions above.

    One solution is to make html codes for all text. Here is a function I have used when all else has failed.

    function span_accent($wordz)
    {
    
    $wordz = str_replace( "Á","&Aacute;",$wordz);
    $wordz = str_replace( "É","&Eacute;",$wordz);
    $wordz = str_replace( "Í","&Iacute;",$wordz);
    $wordz = str_replace( "Ó","&Oacute;",$wordz);
    $wordz = str_replace( "Ú","&Uacute;",$wordz);
    $wordz = str_replace( "Ñ","&Ntilde;",$wordz);
    $wordz = str_replace( "Ü","&Uuml;",$wordz);
    
    $wordz = str_replace( "á","&aacute;",$wordz);
    $wordz = str_replace( "é","&eacute;",$wordz);
    $wordz = str_replace( "í","&iacute;",$wordz);
    $wordz = str_replace( "ó","&oacute;",$wordz);
    $wordz = str_replace( "ú","&uacute;",$wordz);
    $wordz = str_replace( "ñ","&ntilde;",$wordz);
    $wordz = str_replace( "ü","&uuml;",$wordz);
    
    $wordz = str_replace( "¿","&iquest;",$wordz);
    $wordz = str_replace( "¡","&iexcl;",$wordz);
    $wordz = str_replace( "€","&euro;",$wordz);
    $wordz = str_replace( "«","&laquo;",$wordz);
    $wordz = str_replace( "»","&raquo;",$wordz);
    $wordz = str_replace( "‹","&lsaquo;",$wordz);
    $wordz = str_replace( "›","&rsaquo;",$wordz);
    return $wordz;
    }
    
    0 讨论(0)
提交回复
热议问题