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:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I have also made sure that the page header is set for utf-8 also:
header('Content-type: text/html; charset=UTF-8');
Here is the beginning stages of my code thus far:
<?php
setlocale(LC_ALL, 'es_MX');
$datetime = strtotime($event['datetime']);
$date = date("M j, Y", $datetime);
$day = strftime("%A", $datetime);
$time = date("g:i", $datetime);
?>
<a href="/<?= $event['request'] ?>.html"><?= $day ?> <?= $time ?></a>
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.
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 .
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.
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.
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');
Kindly check your file ENCODING. It must be in UTF-8 or UTF-8 without BOM.
To change you file encoding. Use Notepad++(you can use also other editor where you can change the file encoding). In menu bar > Choose ENCODING > Choose any UTF-8 or UTF-8 without BOM.
See link for the difference of UTF-8 and UTF-8 without BOM. What's different between UTF-8 and UTF-8 without BOM?
Hope it can help. :)
Having a similar problem, I found the answer here. Not Displaying Spanish Characters
The resolution was to change from UTF-8 to 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.