I have page, taht loads data from different databases (which could have different charset). Problem is, that it loads with broken charset to UTF-8. And I need to find a way, how to load it propertly.
My connection is:
$db = new PDO("mysql:host=".DBHOST.";dbname=".DBNAME, DBUSER, DBPASS);
$db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
as you can see, I use 'SET NAMES utf8'
I have <meta charset="utf-8"> in <head>
And I have tried some conversions:
error_log("ORGIGINAL: ".$row["title"]);
error_log("ICONV: ".iconv(mb_detect_encoding($row["title"], mb_detect_order(), true), "UTF-8", $row["title"]));
error_log("UTF_ENCODE: ".utf8_encode ($row["title"]));
I believe, I have all files loaded in UTF-8 too (re-saved every file in notepad switching from ANSI to UTF-8. then tried this tool for verification https://nlp.fi.muni.cz/projects/chared/)
now, where fun begins: Not only that I got wrong output, I have different output for browser and error log.
FIREFOX reaction:
Original:
utf8_encode:
iconv: same as utf8_encode
and now, how it was loaded into php error file:
As you can see, the output has best result in original shape, while if trying to convert, it has more deformed output. Also tried to change error log file charset to UTF-8 (original unknown/ANSI probably), but same shape in both encodings)
The text is central-europe/czech. needed characters are: á é ý í ó ú ů ž š č ř ď ť ň ě
So, any ideas, where can be something wrong?
Thanks :)