Usually, when creating a website in PHP and MySQL, there’s a problem when introducing accents and strange characters, typically from foreign languages like Spanish or French: these get changed into Ã¡Ã³Ã± and similar strange stuff.
This happened to me a while ago and I freaked out and started tweaking everything, changing charsets and converting everything to HTML safe like ó but none of these worked or I had such a big database already that it would take ages to change everything manually.
The problem here is that the charset of special characters is not the same in the MySQL database, the PHP language compiler and the Apache server.
So I started to investigate and after some research I’ve made up a step-by-step list of all the essential things you should check and do in order to solve this. 98% of the people that have tried this have been successful.
Step by Step Guide on How to Solve the Encoding Issues with Weird Characters
- When creating the database in MySQL make sure all the string fields have
utf8_spanish_cicharset and the charset of the tables is
utf_unicode_ci(you can change it later in phpMyAdmin going to Operations > Collation)
- Make sure you specify a Content-type in all your HTML files, inside the
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
- And in those files you output without HTML headers (XML, AJAX/JSON calls, APIs…) put this in the PHP:
- When establishing the connection between PHP and MySQL send this query before any other:
mysql_query("SET NAMES 'utf8'");
- Remove the
DefaultCharsetin Apache or modify it
Following these steps will solve the weird accents problem in your server. If it still doesn’t work post a comment below and we’ll help you.
Photo by Eduardo
TrendLiker.com tiene centenares de artículos y te envía un email cuando bajan de precio en Amazon para comprar barato.Buscas ideas para un regalo?