bad_gui Posted May 14, 2008 Share Posted May 14, 2008 I have a journal article DB project that I coded at home. The database character set is UTF-8 since some author names are foreign. I switched my browser's default font to utf-8. The php code includes <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> <TITLE>Virtual Library</TITLE> <STYLE TYPE="text/css"> Everything works great at home. When I installed this at work for general use, I found internet exploder doesn't allow a permanent change to the default character encoding. It also ignores the code above even when I set the encoding to "autodetect" Even if I manually set utf-8, every time I browse away the default is reset to Western (ISO-8859-1 I think). So now the old entries I transfered by mysqldump are mangled when viewing with Western, but the new entries are mangled when viewing with utf-8. I can change all to latin1 but this doesn't cover all French, Spanish Swedish etc. characters, no? I tried searching the web but couldn't find how professional developers (I'm an amateur) deal with the accented character in a mixed browser environment. Several options are listed in this link but which is http://en.wikipedia.org/wiki/Help:Special_characters Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 14, 2008 Share Posted May 14, 2008 PHP 6 has MUCH better Unicode support, but for now, you need to make sure that MySQL is using utf-8 and set it in the page (you did this). Quote Link to comment Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 since some author names are foreign. I switched my browser's default font to utf-8. First a note - utf-8 is a charset, not a font. Fonts display characters. The characters that exist are determined by the charset. If the character doesn't exist in the charset, then the font cant display it. Next, the (potential) solution to your problem: it sounds like the default charset that php is using is set to iso-8859-1 instead of utf-8. To find out if this is the case, create a file and include the following code in it: <?php phpinfo(); ?> Then run that script on your server. It will print out a whole huge list of all the settings you have for php. Look for default_charset (its probably in the top block of settings) and see what it is set to. If it is set to iso-8859-1, you will need to go into your php.ini and change the default charset to utf-8 in there. Quote Link to comment Share on other sites More sharing options...
bad_gui Posted May 16, 2008 Author Share Posted May 16, 2008 Sysadmin at work won't change httpd.conf default charset from iso-8859 but I found a site with useful workaround that solves most of the problem http://www.phpwact.org/php/i18n/charsets So I added the follwing code to the top of index.php and now IE switches to utf-8 when the encoding is set to "auto" This will display the characters correctly on the main page but not when other pages are used. // Setting the Content-Type header with charset header('Content-Type: text/html; charset=utf-8'); However, since I am a newbie to php and html I can't figure out how to apply this to all of the code since some pages still display garbled characters Yuste L, Montero JC, Espar�s-Ogando A, Pandiella A. (2005) Activation of ErbB2 by overexpression or by transmembrane neuregulin results in differential signaling and sensitivity to herceptin. Cancer research 65: 6801-10. But when I do a "view source" in the browser it gives <TABLE BORDER="0" CELLSPACING="5" CELLPADDING="5"><TR><TD><P ALIGN=justify>Yuste L, Montero JC, Esparís-Ogando A, Pandiella A. (2005)<BR> <B>Activation of ErbB2 by overexpression or by transmembrane neuregulin results in differential signaling and sensitivity to herceptin.</B><BR> Cancer research <B>65</B>: 6801-10.<BR> Do I add the php code to set the header to utf-8 to every php script? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 16, 2008 Share Posted May 16, 2008 Add the header to every page, or put it in a headers.php file and include it on every page (so, if the situation demands it, you can add more headers later with only one line more of code in one file). Quote Link to comment Share on other sites More sharing options...
haku Posted May 19, 2008 Share Posted May 19, 2008 I think you need to go back and re-read my post. I didn't say anything about touching the httpd.conf file, and I gave you what I think is most likely the solution to your problem (I regularly deal with encoding issue due to the fact that I am programming Japanese websites). If you ask for help, you should at least attempt the suggestions you are given. 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.