note 29401 deleted from function.addslashes by philip

From: Date: Tue, 20 Jul 2004 17:10:55 +0000
Subject: note 29401 deleted from function.addslashes by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73704@lists.php.net to get a copy of this message
Note Submitter: ---- here are a few functions I use // This function is a generic data processing function. It adds slashes if the magic quotes is off. function reslash($string) { if (!get_magic_quotes_gpc()) $string = addslashes($string); return $string; } // This function takes out slashes if if the magic quotes are on. function deslash($string) { if (get_magic_quotes_gpc()) $string = stripslashes($string); return $string; } I use deslash whenever I print out example: <input name=blah value="<?=deslash($string)?>"> and reslash whenever I put into an sql statement: $query = "update blah set blahblah='".reslash($string)."' " but I never ever do this: $string = deslash($string); or $string = reslash($string); If you do that then you may ruin the original and get confused in your code when reslash does not work on a deslashed string.

« previous php.notes (#73704) next »