Solved: Session is not encoding my string properly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
parka
Forum Commoner
Posts: 52
Joined: Mon Feb 26, 2007 6:48 am

Solved: Session is not encoding my string properly

Post 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?
Last edited by parka on Mon Jan 26, 2009 10:09 am, edited 1 time in total.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Session is not encoding my string properly

Post 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
parka
Forum Commoner
Posts: 52
Joined: Mon Feb 26, 2007 6:48 am

Re: Session is not encoding my string properly

Post 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>
parka
Forum Commoner
Posts: 52
Joined: Mon Feb 26, 2007 6:48 am

Re: Session is not encoding my string properly

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