Using utf8_decode to correct diacritics words

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Using utf8_decode to correct diacritics words

I said in one my earlier articles that I’ve had to upgrade joomla 1.0 to joomla 3.2, not I’m not entirely sure at what point, but at the end, I’ve noticed that all my accent words were binary encoded in the database. This may or may not work in all cases, but see below how used utf8_decode to correct diacritics words in the whole database.

Scenario

Ok, first lets see a simple example, you have the bellow letters you want to correct, of course you can use the complete word, only the encoded letters will be decoded:

As you can see, the letters there are really not the ones you expect.

Solution

A solution to this would be to use the php function utf8_decode(), using this it will convert everything back to normal letters.

Output

Output would then look like you would normally expect:

So as you can see, now the accent letters are shown properly.

Correct the diacritics in the entire database

Of course when talking about a database, we can’t really go through all the tables and correct this, so here’s a little code snippet I made for converting a mysql database directly. Keep in mind though you need to dump the SQL database into an SQL file for this to work.

Warning! Please make a backup of the original SQL database before you make any changes just in case something goes wrong.

You will have there a new sql file sql_file_decoded.sql with your correct utf8 decoded accent content. Now your last step is to restore the mysql database and see if everything works as expected.

Request an article ←