Zoranos Posted March 8, 2012 Share Posted March 8, 2012 Hi, i dont know if anyone have this problem: When i store some value in session and echo that inside <html> tags it wont show utf-8 signs, example: <?php $_SESSION['name'] = "Duško"; ?> <?php echo $_SESSION['name']; ?>//outside of html tag it will print Duško <html> <?php echo $_SESSION['name']; ?>//inside of html it will print: Du?ko <html> I have tried: -with utf8_encode(before storing in session) and later utf8_decode() - doesnt help -i have defined support for utf8 in html(<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />) and defined with header() in php - doesnt help -i have saved with utf8 DOM, without DOM - not working PHP version: 5.3.8 i dont have any solution for that, outside html everything is ok, but inside html tags utf-8 support doesnt work.. does anyone have solution for this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/258552-session-and-utf-8-echo-inside-html-tags/ Share on other sites More sharing options...
kicken Posted March 8, 2012 Share Posted March 8, 2012 Try with utf8_encode, but do not decode it later. The browser will do that when it displays it. Quote Link to comment https://forums.phpfreaks.com/topic/258552-session-and-utf-8-echo-inside-html-tags/#findComment-1325350 Share on other sites More sharing options...
requinix Posted March 8, 2012 Share Posted March 8, 2012 - Keep that tag and/or a header("Content-Type: text/html; charset=utf-8"); - Save without the BOM. Otherwise PHP will incorrectly output that BOM right when it parses the file and you won't be able to use functions like session_start() or header(). Another thing: if you're writing these values inside the PHP file itself (like the code you posted) then the file itself has to be UTF-8 too. Quote Link to comment https://forums.phpfreaks.com/topic/258552-session-and-utf-8-echo-inside-html-tags/#findComment-1325359 Share on other sites More sharing options...
Zoranos Posted March 8, 2012 Author Share Posted March 8, 2012 - Keep that <meta> tag and/or a header("Content-Type: text/html; charset=utf-8"); - Save without the BOM. Otherwise PHP will incorrectly output that BOM right when it parses the file and you won't be able to use functions like session_start() or header(). Another thing: if you're writing these values inside the PHP file itself (like the code you posted) then the file itself has to be UTF-8 too. you didnt read my post... i have try this, no help... but i have debuged and found problem, its not problem in calling session in another file, but with saving utf in session: i use this on user login to store name: <?php $userarray = mysql_fetch_array($result);//$result if from mysql_query $_SESSION['name'] = $userarray['name'];// lest say that name is Duško ?> and when i print that later in html (echo $_SESSION['name'] it will print Du?ko then i tested to store directly string: <?php $_SESSION['name'] = "Duško";// lest say that name is Duško ?> And that will print later if i use this in html Duško... That is weird, its wrong storing name in arraym, or somehow encode that... any solution, suggest? Quote Link to comment https://forums.phpfreaks.com/topic/258552-session-and-utf-8-echo-inside-html-tags/#findComment-1325362 Share on other sites More sharing options...
kicken Posted March 8, 2012 Share Posted March 8, 2012 Make sure your connection to MySQL is set to UTF8 as well. mysql_set_charset Quote Link to comment https://forums.phpfreaks.com/topic/258552-session-and-utf-8-echo-inside-html-tags/#findComment-1325363 Share on other sites More sharing options...
Zoranos Posted March 8, 2012 Author Share Posted March 8, 2012 Make sure your connection to MySQL is set to UTF8 as well. mysql_set_charset thank you so much!!! i didnt remember that... and now i have lost few hours trying to solve this! thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/258552-session-and-utf-8-echo-inside-html-tags/#findComment-1325366 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.