I’m reading a lot about UTF-8 and encoding but I’m lost,
I simply want to parse a string with a GET/POST in php and if it contains something else that UTF-8 to convert it (in my occasion Greek)
so my faulty code is:
$title = $_GET['title'];
//and sometimes I use this:
$info = htmlspecialchars(trim($_GET['info']));
echo $title, $info;
and it echoes λεξη λÎξη1 for some greek characters given (which is wrong of course).
Thanks
Update:
Just wanted to update with my solution in case somebody reads this. The problem was just one line which was missing:
mysql_set_charset('utf8', $con);
With $con of course handling the mysql_connect
You need to know what encoding a string is in. Converting anything and everything from an unknown encoding to UTF-8 is simply not possible. You need to convey through meta information how a certain string is encoded and handle it appropriately. How this is done exactly depends on what exactly you want to do. Preferably you do no encoding conversion at all at any point, but keep everything in UTF-8 front to back.
I’d recommend you look into: