Reputation: 1398
This is really driving me crazy. I'm building a spanish website (meaning a lot of latin characters) and I'm using Zend framework.
When I save a á
it displays like á
. I know is a charset encoding but I dont understand why.
My head charset is <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
My database is utf8_general_ci
. I've changed the charset to others and always the same problem.
When I look in my database, what is saved is an á
Any idea why is this happening? Thanks!
Upvotes: 1
Views: 1885
Reputation: 5072
Here goes the recipe to get rid of encoding headaches:
utf8_unicode_ci
.meta
tag: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
If you have access to MySQL file configuration my.cnf
just add this line:
init-connect='SET NAMES utf8'
This tells MySQL to return results in UTF-8 for each connection.
If you cannot edit my.cnf
but you are using PDO, open the connection this way:
$pdo = new PDO($dsn, $usr, $pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
If you aren't using PDO... start using it, what are you waiting for? Meanwhile you can execute this after each connection if you use ext/MySQLi:
$mysql->set_charset('utf8');
Or this if you use plain old ext/MySQL:
mysql_set_charset('utf8', $connection);
Upvotes: 1
Reputation: 86346
The character á
and other characters outside the ASCII map can be mapped with unicode
.
As you are stroing the data in a table with UTF-8
charset and characters are storing properly.
I would suggest you that
Run the query SET NAMES UTF-8
. This will fetch your UTF-8
data with taking care of the characters which are outside of ASCII map.
While outputting the data you make sure that you are forcing/directing browser to use the UTF-8
charset to print the data.
Upvotes: 0