Skip to content
Advertisement

Spanish Characters not Displaying Correctly

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:

JavaScript

I have also made sure that the page header is set for utf-8 also:

JavaScript

Here is the beginning stages of my code thus far:

JavaScript

The above code is in a where statement. I have read that switching the collation in the database can also be a factor but I already have it set to UTF-8 General ci. Plus, the only thing that is in that column is DateTime anyway which is numbers and cannot be collated anyway.

result: s�bado 8:00

Any help is greatly appreciated as always.

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement