Page 1 of 1
Solved: Session is not encoding my string properly
Posted: Mon Jan 26, 2009 8:43 am
by parka
It seems like my sessions are not encoding my string properly. I can't seem to remember needing to set the encoding or charset or whatever.
Here's my code.
Code: Select all
$sString = 'television’s';
$_SESSION['badstring'] = $sString;
echo $_SESSION['badstring'];
// Prints televisionÕs
Note the typographer's quote mark after the word 'television'.
It prints
televisionÕs instead of
television’s
Any ideas how to solve this?
Re: Session is not encoding my string properly
Posted: Mon Jan 26, 2009 9:01 am
by Mark Baker
parka wrote:It seems like my sessions are not encoding my string properly. I can't seem to remember needing to set the encoding or charset or whatever.
Sessions don't encode strings, they simply hold them as entered.
Try setting the page where you're displaying the value to utf-8
Re: Session is not encoding my string properly
Posted: Mon Jan 26, 2009 9:08 am
by parka
Mark Baker wrote:parka wrote:It seems like my sessions are not encoding my string properly. I can't seem to remember needing to set the encoding or charset or whatever.
Sessions don't encode strings, they simply hold them as entered.
Try setting the page where you're displaying the value to utf-8
Thanks.
What do you mean by displaying the value to utf-8? I've set my meta tag to that.
Here's my php page and accompanying html output.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
$sString = 'television’s';
echo $sString;
?>
</body>
</html>
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
television?s</body>
</html>
Re: Session is not encoding my string properly
Posted: Mon Jan 26, 2009 10:08 am
by parka
Thanks.
I think it's the encoding for my .php file. When saved as a UTF-8 encoding, the echo() command works ok.