Stripslashes if magic quotes enabled

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
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Stripslashes if magic quotes enabled

Post by alex.barylski »

I recall having a snippet of code in my application that checked for magic quotes and stripped quotes if nessecary using a recurvsive method. I searched google breifly and php.net and found this snippet:

Code: Select all

function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);
 
    return $value;
}
I wrap this in a simple if() to test whether magic quotes are on or not and voila!!!

Can anyone see any enhancements or issues with this approach...

Cheers,
Alex
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Stripslashes if magic quotes enabled

Post by requinix »

Seems fine to me. Remember to execute this only if magic_quotes is enabled.
Post Reply