2

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

Diolor
  • 13,181
  • 30
  • 111
  • 179
  • See this may be help you http://stackoverflow.com/questions/13172660/language-translation-using-php/13173435#13173435 – Hkachhia Nov 08 '12 at 09:59
  • Other link http://stackoverflow.com/questions/13208149/php-with-special-characters-like-n/13208272#13208272 – Hkachhia Nov 08 '12 at 10:00
  • @Harry isn't something more simple like that: http://www.php.net/manual/en/reserved.variables.get.php#105335 (which I cannot understand how to use) Or add a `ENT_QUOTES,"UTF-8"` on my `$_GET` ? – Diolor Nov 08 '12 at 10:04
  • @DDL499 Use html_entity_decode() function I think your problem is solved – Hkachhia Nov 08 '12 at 10:09

1 Answers1

3

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:

deceze
  • 510,633
  • 85
  • 743
  • 889