Jump to content

Session and utf-8 echo inside html tags


Zoranos

Recommended Posts

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

Link to comment
Share on other sites

- 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.

Link to comment
Share on other sites

- 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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.