gdfhghjdfghgfhf Posted October 3, 2009 Share Posted October 3, 2009 I have a weird problem related to characters encoding on my website I have using a phpbb3 forum, and i have a french and russian forum. I have built a menu showing the last posts of all forums My problem is that when a post title includes weird character (french characters like "é à â î Ç" or russian characters) it will display incorrectly I don't understand why, because the characters are displayed correctly inside the forums What do i have to do? Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/ Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Are you setting the encoding type of the page... with either something like this in the head section.. <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" /> or with the PHP header() function? Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-929646 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted October 3, 2009 Author Share Posted October 3, 2009 i already tryed that, just tryed again and it doesnt change anything see by yourself: http://www.anarcho-punk.net/ this is the script where the problem comes from (i include() this menu on the front page) http://www.anarcho-punk.net/last2.php As you can see the russian topic name is written "????????" but when you click on the link, everything is good: http://www.anarcho-punk.net/viewtopic.php?f=5&t=1981 Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-929692 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Had a quick look at the headers sent with your site, the difference between the working one and the other one seems to be... Content-Type: text/html; charset=UTF-8 Try calling this at the top of your page... header("Content-Type: text/html; charset=UTF-8"); Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-929701 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted October 4, 2009 Author Share Posted October 4, 2009 if i put it in "last2.php" menu it will write an error message saying the header has already been sent So i replaced the current charset with your code in phpbb header's template..... But i still have the same problem Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-929968 Share on other sites More sharing options...
nrobi Posted October 4, 2009 Share Posted October 4, 2009 The header() call must be the VERY first thing in the file. No newlines, no nothing. The alternative is to turn on output buffering then you can pretty much put it anywhere you want. Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-929983 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted October 4, 2009 Author Share Posted October 4, 2009 The header() call must be the VERY first thing in the file. No newlines, no nothing So this is probably the problem. I need to set UTF-8 in the left menu of my site. So if i put the header() call inside my left menu script, it will not be the very first thing in the file when index.php loads Even if i put the code in the first line of "last2.php", i get this error: [phpBB Debug] PHP Notice: in file /last2.php on line 1: Cannot modify header information - headers already sent by (output started at /cache/tpl_Dark-Shines_overall_header.html.php:2) so i have tryed to put the PHP code inside the beginning of "overall_header.html" but it doesn't change anything Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-929991 Share on other sites More sharing options...
nrobi Posted October 4, 2009 Share Posted October 4, 2009 If the problem still remains.... is there any differences in the MySQL code for the homepage and viewtopic.php? There may be a line like: mysql_query("SET NAMES 'charset_name'"); Where charset_name is UTF8, utf-8, utf8, or UTF-8. Something to try in addition to the header() call if it still isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-930070 Share on other sites More sharing options...
cags Posted October 4, 2009 Share Posted October 4, 2009 I did a quick search and came across somebody that claims this solved their problem using... mysql_query("SET CHARACTER SET utf8"); mysql_query("SET NAMES utf8"); ... which is a slight addition to nrobi's suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-930076 Share on other sites More sharing options...
gdfhghjdfghgfhf Posted October 5, 2009 Author Share Posted October 5, 2009 WOOHOO! thanks a lot cags, it worked! Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-930402 Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 Glad it's fixed for you btw, can you mark the topic as solved, (bottom left corner). Quote Link to comment https://forums.phpfreaks.com/topic/176383-problem-with-character-encoding/#findComment-930617 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.