Turn off Addslashes

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
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Turn off Addslashes

Post by nickman013 »

Hello,

I want to know how to turn off add slashes or remove slashes w/e it is. I have slashes that appear next to ' and " and it gets very annoying. Can I turn thiss off in my php.ini?

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yes, you can turn it off in php.ini, however you should write your scripts to support the functionality being on or off.

get_magic_quotes_gpc() and get_magic_quotes_runtime() are used to detect when to run stripslashes() on a value.

The manual pages detail what php.ini settings affect them. Take notice of the notes placed on the pages too.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

here is a function written by arborint that removes those slashes... it can handle either a standard value (string) or an array of values (strings):

Code: Select all

function removeSlashes(&$var) {
        if (is_array($var)) {
            foreach ($var as $name => $value) {
                if (is_array($value)) {
                    removeSlashes($value);
                } else {
                    $var[$name] = stripslashes($value);
                }
           }
        } else {
            $var = stripslashes($var);
        }
    }
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Thanks!!!
Post Reply