Displaying pre-escaped varibles

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
marty pain
Forum Contributor
Posts: 105
Joined: Thu Jun 11, 2009 5:32 am
Location: Essex

Displaying pre-escaped varibles

Post by marty pain »

Just a quick one.

I'm displaying a users name on the screen after they log in. The name is escaped when it was saved to the database so, for example:

Steve 'the idiot' Austin is displayed as Steve \'the idiot\' Austin

Do I have to use str_replace() to swap '\' out, or can I read them in or display them in a way to sort it out?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Displaying pre-escaped varibles

Post by AbraCadaver »

Use stripslashes(), however there are several possible reasons for your problem. Either magic_quotes_gpc() is enabled and then the data was manually escaped again before insert or magic_quotes_runtime() is enabled and the data is escaped when it comes out of the database. You should really turn of magic_quotes_* as it is deprecated and will be removed, plus it causes these sorts of problems.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
marty pain
Forum Contributor
Posts: 105
Joined: Thu Jun 11, 2009 5:32 am
Location: Essex

Re: Displaying pre-escaped varibles

Post by marty pain »

Excellent. Thanks mate.

magic_quotes_gpc() was set on, so the string was being escaped twice.

Turned it off and re-entered the string and now it's all ok.

Thanks,
Steve
Post Reply