Problem with character like ' " /

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
loonyew
Forum Newbie
Posts: 4
Joined: Tue Mar 24, 2009 11:51 am

Problem with character like ' " /

Post by loonyew »

Hi there, need help on this....TQ very much

The character ' is giving me problem on this

<textarea name="message"></textarea>

whenever i submit the textarea and i echo back the contents


Customer's Name is Johnson

will become

Customer\'s Name is Johnson


That is "abc"

will become

That is \"abc\"


You can choose either\

will become

You can choose either\\

tried with
echo $_Request[ 'message' ] --->produce the red result

$temp = $_Request[ 'message' ];
echo $temp --->produce the red result
wellhole
Forum Newbie
Posts: 16
Joined: Mon Mar 23, 2009 1:38 pm

Re: Problem with character like ' " /

Post by wellhole »

try echo "$temp"
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem with character like ' " /

Post by requinix »

Won't help in the least bit.

It's called magic quotes. With this INI setting on, PHP automatically runs addslashes on all input, which escapes things like quotes and backslashes.

Turn it off in php.ini, in a .htaccess with

Code: Select all

php_flag magic_quotes_gpc off
or, as a last resort if you can't do either, run everything through stripslashes before trying to use it, like

Code: Select all

echo stripslashes($_Request['message']);
loonyew
Forum Newbie
Posts: 4
Joined: Tue Mar 24, 2009 11:51 am

Re: Problem with character like ' " /

Post by loonyew »

Thank for the reply...got the solutions something like tasairis

if(get_magic_quotes_gpc()){ //check wheher the mgic quotes gpc is tunrned on

$message=stripslashes($_REQUEST[ 'txtMessage' ]);

}else{
//magic quotes gpc is turned off....so not need use stripslashes
$message=$_REQUEST[ 'txtMessage' ];

}
Post Reply