Forum Moderators: coopster

Message Too Old, No Replies

strip / addslashes

         

matthewwithanm

8:43 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Could somebody please explain to me why

echo addslashes ( stripslashes ( $stuff ) );

does not output the same thing as

echo $stuff;

?

Thanks.

ChadSEO

9:30 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



If $stuff contains single quotes, double quotes, backslashes or NULL bytes that are already escaped (they have a backslash before them), then it will print the same thing. However, if they are not escaped, then it will do it for you.

The benfit of that statement is to ensure that these special characters do have a backslash before them, and that it's not repeated. If the characters are already escaped, then stripslashes will remove them; if not, then stripslashes does nothing.

matthewwithanm

11:08 pm on Aug 9, 2005 (gmt 0)

10+ Year Member



Thanks but I don't think that's exactly what I'm asking..

I have an escaped string:

$tmp = 'he\\o';

When I echo it, I get 'he\o'. So far, everything's good. However, when I do

echo addslashes ( stripslashes ( $tmp ) )

I get 'heo'. Why don't I get 'he\o' again? Thanks.

EDIT:

I'm so confused..

addslashes ( stripslashes ( 'he\\\\o' ) )

correctly evaluates to 'he\\o' but

addslashes ( stripslashes ( 'he\\o' ) )

echos as 'heo'.

matthewwithanm

12:19 am on Aug 10, 2005 (gmt 0)

10+ Year Member



Forget it.