lonelycastle Posted September 13, 2007 Share Posted September 13, 2007 Alright, so I have a mysql database full of location names from around the world. Needless to say, there's a lot of unusual characters. The database and each table within it has a utf8_general_ci collation and all the rows appear fine within the database: Examples: Nichiyō Seamount 嫁島海山 Kobilovača Bom Princípio do Piauí I have this in the header: <meta http-equiv="content-type" content="text/html; charset=UTF-8"> And I utf8_encode all the info I get from the database: utf8_encode($qry[title]); This works for basic symbols: Bom Princípio do Piauí Cidelândia São José da Safira But not for some of the more complex ones: ?uri?a Staje (should be Ćurića Staje) ???? (should be سوت) Gy?ja-zan (should be Gyōja-zan) I know very little about character encoding or how to make sure everything (especially the communication between the database and website) is using utf8. Any help you could offer would be great. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/ Share on other sites More sharing options...
thedarkwinter Posted September 13, 2007 Share Posted September 13, 2007 Hi I'm not sure why some characters are working and not others. My db and my html are in utf-8 and i dont use utf8_encode() function - and all non-latin including Chinese and Arabic shows fine One suggestion which could just be plain silly, is to change the font your are outputting the data in. That may have an effect? Cheers, tdw Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347760 Share on other sites More sharing options...
effigy Posted September 13, 2007 Share Posted September 13, 2007 And I utf8_encode all the info I get from the database MySQL should handle this for you. See this topic. Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347765 Share on other sites More sharing options...
lonelycastle Posted September 13, 2007 Author Share Posted September 13, 2007 Right now I'm not even applying a font. It's just the typical Arial or whatever is the standard web font. Also, if I don't use the utf8_encode, none of the unusual characters work (ã, í, etc. don't work). Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347768 Share on other sites More sharing options...
effigy Posted September 13, 2007 Share Posted September 13, 2007 To reiterate, have you tried using SET CHARACTER SET charset_name when connecting to MySQL? Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347811 Share on other sites More sharing options...
lonelycastle Posted September 13, 2007 Author Share Posted September 13, 2007 To reiterate, have you tried using SET CHARACTER SET charset_name when connecting to MySQL? I don't know much about how to change the MySQL connection. My brother usually does that stuff, but he's at class at the moment. If you could tell me what to look for [what the connection code looks like] I could try and figure it out. Which looks more like the connecting code: $CONNECT_SLAVE = myC("SLAVE"); $CONNECT_MASTER = myC("MASTER"); .. both of which go to a function which does this: $link_identifier = mysql_connect($_DB[$server_group][$r]['IP'], $_DB[$server_group][$r]['USER'], $_DB[$server_group][$r]['PASS']) or error_mysql("Connect - ".$_DB[$server_group][$r]['PASS']); or mysql_query("USE `".$database."`", $link_identifier) or error_mysql("USE `".$database."`"); or $resource = mysql_query("$query", $link_identifier) or error_mysql($query); I know I'm an idiot, but thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347828 Share on other sites More sharing options...
effigy Posted September 13, 2007 Share Posted September 13, 2007 After you've connected to MySQL, try running these: mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347833 Share on other sites More sharing options...
lonelycastle Posted September 13, 2007 Author Share Posted September 13, 2007 That fixed it. Thanks a bunch. Also, just a quick question. When I have forms on the website, do I have to utf8_encode them before I submit them or do I have to do anything different to allow users to type unusual characters in my forms? Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347854 Share on other sites More sharing options...
effigy Posted September 13, 2007 Share Posted September 13, 2007 As long as the form knows you're using UTF-8 via the meta tag, and MySQL knows you're using UTF-8 via SET CHARACTER SET, everything should be transparent. This is how I understand it: A user types/pastes "¶" into your form and submits. The submitted data is now "¶", the UTF-8 encoding for "¶", because your meta tag said use UTF-8. When you connect to MySQL you instruct it to use UTF-8, and since your data is already there, you simply drop it in. The same applies when pulling data out. You tell MySQL to use UTF-8, it gives you UTF-8, and you tell the browser to render UTF-8, and it does so. Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347869 Share on other sites More sharing options...
lonelycastle Posted September 13, 2007 Author Share Posted September 13, 2007 Thanks a lot effigy. You've saved me days of fiddling around. Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-347908 Share on other sites More sharing options...
Kleidi Posted May 15, 2011 Share Posted May 15, 2011 After you've connected to MySQL, try running these: mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); This solution helped me too, but, what about text that does not come from db but from the php/html file? After i applied the solution you suggested, was resolved the apparition of non-latin letters that comes from the db but not the letter that comes from the file. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/69192-solved-trouble-working-with-utf-8-characters/#findComment-1215640 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.