note 29401 added to function.addslashes
| From: | php-general at lists dot php dot net | Date: | Wed, 12 Feb 2003 16:52:35 +0000 |
| Subject: | note 29401 added to function.addslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43827@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/function.addslashes.php
http://master.php.net/manage/user-notes.php?action=edit+29401
http://master.php.net/manage/user-notes.php?action=delete+29401
http://master.php.net/manage/user-notes.php?action=reject+29401