son Posted October 8, 2010 Share Posted October 8, 2010 Hi there,I am struggling (again) with special characters of other European languages (Swedish, French, Polnish and German). Cannot get my head around this as I took all measures to ensure that characters display ok, but when I get data from database field (collation set to UTF-8) those characters don't display properly. I have at the top of my script: header('Content-Type: text/html;charset=utf-8');mysql_set_charset($GLOBALS['DB'], 'utf8'); and I have also done a save as with Notepad to make sure the actual file is saved correctly. Also, when I copy the data from database and directly paste into html code it displays fine. Only when it comes out from database the issue appears. This does not make sense to me. What else could influence the display of those characters? In my sql loop to go through data I simply get the data via$desc = $row['desc_de'];Son Link to comment Share on other sites More sharing options...
boen_robot Posted October 10, 2010 Share Posted October 10, 2010 Are you sure the charset call is applied successfully?Looking at the manual page for mysql_set_charset(), it seems the arguments must be in reverse order, so the call has probably failed. Link to comment Share on other sites More sharing options...
son Posted October 10, 2010 Author Share Posted October 10, 2010 Are you sure the charset call is applied successfully?Looking at the manual page for mysql_set_charset(), it seems the arguments must be in reverse order, so the call has probably failed.I was totally off the mark,mysql_set_charset('utf8', $dbc);was actually the correct way as I hadif ($dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) to connect to database (for some reason forgot to change my code for this new web project with slightly different code)However, it still does not solve my issues... Characters as:Sträckan är fri!not displaying correctly....Son Link to comment Share on other sites More sharing options...
son Posted October 11, 2010 Author Share Posted October 11, 2010 Just to also say that running phpinfo() showed that PHP version 5.2.10 is installed, so that side of things should be fine. However using mysql_client_encoding($dbc) showed that a the latin charset is used. Where does this come from?Son Link to comment Share on other sites More sharing options...
boen_robot Posted October 11, 2010 Share Posted October 11, 2010 Note: This function requires MySQL 5.0.7 or later.Is your MySQL server that version or a newer? Link to comment Share on other sites More sharing options...
son Posted October 11, 2010 Author Share Posted October 11, 2010 Is your MySQL server that version or a newer?It is "MySQL 5.1.20-beta-log", so newer version...Son Link to comment Share on other sites More sharing options...
boen_robot Posted October 11, 2010 Share Posted October 11, 2010 Only data created after all of these settings can be read properly. Try to do an INSERT with these things, and see if that displays properly afterwards... it should.If you already have other data created without those settings, you'll have to convert it and reinsert it for it to be displayed properly.If even the newly inserted data doesn't display properly... it's about time to stop guessing. See what error message you get when you try to set the charset like this: if (!mysql_set_charset('utf8', $dbc)) {die('Error ' . mysql_errno() . ':' . mysql_error());} Link to comment Share on other sites More sharing options...
son Posted October 11, 2010 Author Share Posted October 11, 2010 Only data created after all of these settings can be read properly. Try to do an INSERT with these things, and see if that displays properly afterwards... it should.If you already have other data created without those settings, you'll have to convert it and reinsert it for it to be displayed properly.If even the newly inserted data doesn't display properly... it's about time to stop guessing. See what error message you get when you try to set the charset like this:if (!mysql_set_charset('utf8', $dbc)) {die('Error ' . mysql_errno() . ':' . mysql_error());}else{echo "ok";} and it showed ok.Son Link to comment Share on other sites More sharing options...
boen_robot Posted October 11, 2010 Share Posted October 11, 2010 It also depends on how you connected with phpMyAdmin. Upon logging in, phpMyAdmin has an option for the encoding it is going to use. THAT must also be set to UTF-8 before you enter any data. What that option does is essentially the same you're trying to do with mysql_set_charset(). Link to comment Share on other sites More sharing options...
son Posted October 11, 2010 Author Share Posted October 11, 2010 It also depends on how you connected with phpMyAdmin. Upon logging in, phpMyAdmin has an option for the encoding it is going to use. THAT must also be set to UTF-8 before you enter any data. What that option does is essentially the same you're trying to do with mysql_set_charset().sorry, boen_robot. Must have edited my post at same time as you replied.I have runif (!mysql_set_charset('utf8', $dbc)) {die('Error ' . mysql_errno() . ':' . mysql_error());}else{echo "ok";} and it showed ok. Also, the settings in database were all correct before I entered any data...Son Link to comment Share on other sites More sharing options...
son Posted October 11, 2010 Author Share Posted October 11, 2010 Is there anything else I can check? I spent all day now and still have not a clue why this is not working...Son Link to comment Share on other sites More sharing options...
son Posted October 11, 2010 Author Share Posted October 11, 2010 I just found that I established my database connection after header('Content-Type: text/html;charset=utf-8');mysql_set_charset('utf8', $dbc);Bringing the connection before solved the issues special characters (mysql_client_encoding($dbc) shows now UTF-8), yeah! All solved. Many thanks for the great pointers:-)SonReason for edit: solved issue right after post Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.