ayok Posted December 10, 2009 Share Posted December 10, 2009 Hi, I'm trying to insert european characters to mysql such as ë, é, etc. However I've got strange character in my database. How can I encode this chars into html like ë, or é? I used code like echo str_replace("ë","ë",$txt); But it's not working. Would anyone help? thank you, ayok Quote Link to comment Share on other sites More sharing options...
Zyx Posted December 10, 2009 Share Posted December 10, 2009 And have you set the encoding properly? Just give UTF-8 encoding to: 1. MySQL connection: SET NAMES 'utf8'; 2. MySQL columns (collations), tables and database. 3. Set the website charset: header('Content-type: text/html;charset=utf-8'); Or maybe you HAVE set UTF-8 in the database, but you haven't for the rest of the PHP script. Anyway, I think the problem comes from the fact that you have forgotten or do not understand the concept of character encodings. echo str_replace("ë","ë",$txt); It is not supposed to work, if you saved the script in ISO-8859-1 and you try to convert texts i.e. in UTF-8. And I DO NOT recommend converthing them to entities. They will work in nothing but HTML and moreover, the entities do not cover ALL european characters. Quote Link to comment Share on other sites More sharing options...
ayok Posted December 11, 2009 Author Share Posted December 11, 2009 Thank you Zyx, No, i think i still don't understand the concept of character encodings. On the top of my index.php there is <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />, is that not enough? So what's should I better do? I use phpmyadmin, and I see the column "collation" if I make a new table. Should I set this to utf8_unicode_ci? Quote Link to comment Share on other sites More sharing options...
ayok Posted December 11, 2009 Author Share Posted December 11, 2009 anyone? Quote Link to comment Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 Collation should be set to utf8 yes. You will also need.. mysql_query("SET NAMES 'utf8'"); ... and possibly... mysql_query("SET CHARACTER SET 'utf8'"); ...directly after connecting to your database for it to work. Combined with the HTML meta tag you have that should fix it. Quote Link to comment Share on other sites More sharing options...
ayok Posted December 11, 2009 Author Share Posted December 11, 2009 Ok cags, I'll try it and get back if still have problem. Thank you very much! Quote Link to comment Share on other sites More sharing options...
Zyx Posted December 11, 2009 Share Posted December 11, 2009 No, in case of UTF-8, most browsers ignore the META tags - this is why you must send a HTTP header, as I said: header('Content-type: text/html;charset=utf-8'); Ad. MySQL collations. Actually, utf8_unicode_ci is enough for most of people on the planet. It specifies the general sorting order for UTF-8 strings according to the national characters. The other collations are just the extensions of the general UTF-8 collation that apply some extra language-specific sorting rules. For example, French is perfectly covered by utf8_unicode_ci and it does not require any special collation. On the other hand, Polish has such rules and it has its own collation: utf8_polish_ci. And because this is an extension, it still works perfectly for French. cags -> SET NAMES 'utf8' is enough for a connection . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.