quick question - stripslashes & magic quotes...

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
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

quick question - stripslashes & magic quotes...

Post by batfastad »

Our server has magic quotes set to 'on'

Is there anyway I can disable the magic quotes option on my ISP for just one script?

Also the stripslashes() function, does that remove all back slashes in the string?
So if someone typed...

example\example

Then the \ would get removed?

Or does stripslashes just get rid of the ones that are commenting out other characters?
Like these ' " \

Thanks

Ben
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Post by batfastad »

OK so I think stripslashes remove all slashes.

Is there a way to just remove the slashes that are escaping characters after it?

I've tried this...

Code: Select all

// REPLACE ANY COMMENT SLASHES IN THE MESSAGE BODY
$messagestripped1 = str_replace("\''", "''", $message);
$messagestripped2 = str_replace("&quote;", """, $messagestripped1);
But I'm getting errors...

Code: Select all

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /files/home1/dealerworld/dwc-content/eclubsubscribe.php on line 133
I don't want to remove any slashes if the user enters them, or even enters two of them in a row.

I thought the above code should work but it isn't.

Any ideas?

Thanks

Ben
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

From what I can remember stripslashes should only remove the escping slashes - it shouldn't mess things up with backslashes that are supposed to be there.

I useed to use with Windows file paths where there would be C:\\MyWebs\\Somesite\\index.php etc to make it go to c:\Mywebs\somesite\index.php since example\example has no escaping backslashes it shouldn't play with it ;-)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

coming in, example\example should look like example\\example. stripslashes() should bring it back to where it's supposed to be for general use.
ianlandsman
Forum Newbie
Posts: 24
Joined: Thu Dec 30, 2004 9:50 pm
Location: New York

Post by ianlandsman »

The best thing to do is use the function set_magic_quotes_runtime to disable magic quotes (or enable). Either way this function lets you set if quotes are escaped or not. This way you never have to guess if they are you simple set them the way you like them and then code the rest of your program with the runtime set to a known value.

http://us4.php.net/manual/en/function.s ... untime.php
Post Reply