azazel141 Posted February 28, 2008 Share Posted February 28, 2008 I have this in head: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> This in body: <select name="land" size="1" onchange="showRegio(this.value)"> <option value="default">Kies een land..</option> <?php $query = "SELECT name, landid FROM land"; $sql = mysqli_query($mysqli, $query); while($record = mysqli_fetch_object($sql)) { echo '<option value="'.$record->landid.'">'. $record->name.'</option>'; } ?> </select> But when look at the values inserted from the DB I see questionmarks where there should be an 'ë'. ex: Belgi? and Argentin?. This should be->België and Argentinië. A solution I found but I'm not happy with: utf8-encode($record->name) I have lots and lots more of these lists and labels and I don't think surrounding every value with utf8-encode() is the most efficient way of programming. Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 Do you have access to your php.ini file? If so, check what the default encoding is. I'm guessing its probably ISO-8859-1. Or if you are getting this text from a database, the database probably isn't set to UTF-8. Check these two things first. Im thinking its probably the first one though. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 28, 2008 Share Posted February 28, 2008 http://us3.php.net/manual/en/function.utf8-encode.php Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 That's kind of a band-aid solution. If he is going to program a utf-8 site, then he should set everything to utf-8 so that he doesn't have to make unnecessary charset conversions. Quote Link to comment Share on other sites More sharing options...
azazel141 Posted February 28, 2008 Author Share Posted February 28, 2008 Like you said the default_charset in my php.ini file was set to ISO-8859-1. I changed it to empty "" and restarted apache. I also checked my database collation and that was set to utf-8. But I still get the questionmarks. Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 Dont change it to empty, change it to utf-8. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 28, 2008 Share Posted February 28, 2008 I am not sure if this matters, but does the font you are using support characters like 'ë'? Quote Link to comment Share on other sites More sharing options...
azazel141 Posted February 28, 2008 Author Share Posted February 28, 2008 Same problem. Tried both default_charset = "utf-8" and default_charset = "". It's now set to utf-8 and after restarting apache I still get the questionmarks. Font I use: Arial Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 Leave the default charset as utf-8, thats important. First a question: If you go to view -> character encoding in your browser window, what is the setting? Next: Is the text that is coming out as question marks dyamic (from the database) or hard coded into the document? Quote Link to comment Share on other sites More sharing options...
effigy Posted February 28, 2008 Share Posted February 28, 2008 You need to instruct MySQL to use UTF-8: http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html Quote Link to comment Share on other sites More sharing options...
azazel141 Posted February 28, 2008 Author Share Posted February 28, 2008 Answer to first question (im using firefox btw): Unicode(UTF- Answer to second question: As you can see in the code I posted it is retrieved from a database. The $record->naam gives a name of a country. Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 Ok, lets double check to make sure you definitely have your charset set correctly in php. Create a new file, and add echo phpinfo() into the file (sorry I cant put this in code tags, it screws up this site) Then upload that file to your server and run it. Look under php core, and make sure it says utf-8 under the default charset. I'll let you know what to try after that. Quote Link to comment Share on other sites More sharing options...
azazel141 Posted February 28, 2008 Author Share Posted February 28, 2008 I read the site effigy proposed and I solved the problem by executing a SET NAMES utf8; query right after making a connection to the database. Thank you all for the help. This was my first experience with phpfreaks and I am astonished by the quick and professional replies. *now trying to find the topic solved button* Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 The topic solved button is broken. That was going to be my next suggestion, but I wanted to make sure that you had the correct encoding first. Encoding is a hassle! I work in a Japanese company, so I have to do Japanese encoding for our sites. I've had more headaches from that than I can count! Quote Link to comment Share on other sites More sharing options...
thebadbad Posted February 28, 2008 Share Posted February 28, 2008 I always use <?php mysql_query("SET NAMES 'utf8'", $connection); mysql_query('SET CHARACTER SET utf8', $connection); ?> before a query. Quote Link to comment Share on other sites More sharing options...
haku Posted February 28, 2008 Share Posted February 28, 2008 I have that (for Japanese encoding) right after my connection to the database, so that I dont even have to think about it. Its all part of an file that I include at the top of all my scripts. 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.