0

I changed my hosting company and now I'm having problem with non-English characters.

UTF8 encoded text in the database:

ΣτεÏεά Ελλάδα

When I use utf8_decode php function, it returns this:

Σ�?ερεά �?λλάδα

But the text should be:

Στερεά Ελλάδα

What's the problem here? Why does utf8_decode not work? what's the easiest way to fix this?

Dion Russell
  • 93
  • 1
  • 9
  • when you stored them in database, did you use any method to encode them as UTF-8? or you just inserted them to DB? – Ray A Oct 28 '18 at 07:05
  • Not sure how your meta tags looks like, but you should add inside tag in HTML. Also if you're getting data from database and you're using PDO, you should put $pdo->query("SET NAMES 'utf8'"); – Aleksandar Rakic Oct 28 '18 at 07:06
  • Hello, I just inserted them. I use in head, i also use header('Content-type: text/html; charset=UTF-8'); header in php – Dion Russell Oct 28 '18 at 07:10
  • and i also use $db->query("SET NAMES 'utf8'"); as well – Dion Russell Oct 28 '18 at 07:22
  • 1
    Possible duplicate of [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – gp_sflover Oct 28 '18 at 07:31
  • All it takes, is one wrong charset setting in your application - *everything* needs to be the same charset! I have previously written [**an answer about UTF-8 encoding**](https://stackoverflow.com/a/31899827/4535200) that contains a little checklist, that will cover *most* of the charset issues in a PHP/MySQL application. There's also a more in-depth topic, [**UTF-8 All the Way Through**](https://stackoverflow.com/q/279170/4535200). Most likely, you'll find a solution in either one or both of these topics. – Qirel Oct 28 '18 at 07:33
  • @Qirel yep, i tried that but still the same result :( – Dion Russell Oct 28 '18 at 07:49
  • Like it says in my answer, the data that has already been inserted will not be updated if it has the wrong encoding. Fix the broken charset, by following all the points in my answer, then re-insert or update the data in the database. – Qirel Oct 28 '18 at 08:06
  • You should also not use any of the `utf8_encode()`/`utf8_decode()` functions – Qirel Oct 28 '18 at 08:07
  • 1
    The encoding could be messed up or misunderstood in any number of places. Please extract a [mcve], so that all except one of these places is ruled out. – Ulrich Eckhardt Oct 28 '18 at 08:37
  • running `utf_encode('Στερεά Ελλάδα')` returns **ΣÏεÏεά Îλλάδα** and not **ΣτεÏεά Ελλάδα** as in your db. Please verify why there are 2 commas in your encoded value – Jaswinder Oct 28 '18 at 09:49

0 Answers0