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:
&
Use utf8mb4
or Windows-1252
ini_set('default_charset', 'utf8mb4');
or
header('Content-Type: text/html; charset=utf8mb4');
then use tag,
<meta charset="utf8mb4">
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.
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 .
Things to consider in PHP/MySQL/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');
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.
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( "Á","Á",$wordz);
$wordz = str_replace( "É","É",$wordz);
$wordz = str_replace( "Í","Í",$wordz);
$wordz = str_replace( "Ó","Ó",$wordz);
$wordz = str_replace( "Ú","Ú",$wordz);
$wordz = str_replace( "Ñ","Ñ",$wordz);
$wordz = str_replace( "Ü","Ü",$wordz);
$wordz = str_replace( "á","á",$wordz);
$wordz = str_replace( "é","é",$wordz);
$wordz = str_replace( "í","í",$wordz);
$wordz = str_replace( "ó","ó",$wordz);
$wordz = str_replace( "ú","ú",$wordz);
$wordz = str_replace( "ñ","ñ",$wordz);
$wordz = str_replace( "ü","ü",$wordz);
$wordz = str_replace( "¿","¿",$wordz);
$wordz = str_replace( "¡","¡",$wordz);
$wordz = str_replace( "€","€",$wordz);
$wordz = str_replace( "«","«",$wordz);
$wordz = str_replace( "»","»",$wordz);
$wordz = str_replace( "‹","‹",$wordz);
$wordz = str_replace( "›","›",$wordz);
return $wordz;
}