note 43926 added to function.addslashes
| From: | dragon_rage4 at hotmail dot com | Date: | Thu, 08 Jul 2004 20:47:01 +0000 |
| Subject: | note 43926 added to function.addslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72894@lists.php.net to get a copy of this message | ||
I tried using the example from 2002 for doing addslashes() recursively on arrays, but PHP was
throwing notices. So I wrote my own that keeps out the "Undefined variable" notices. This
works on strings and arrays, so you don't have to worry about the variable type.
<?php
if (!function_exists("slash"))
{
function slash ($var)
{
$new_var = "";
if (!is_array($var))
{
unset($new_var);
$new_var = addslashes($var);
} else
{
foreach ($var as $key => $value)
{
unset($new_var);
if (!is_array($value))
{
$new_var[$key] = addslashes($value);
} else
{
$new_var[$key] = slash($value);
}
}
}
return $new_var;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.addslashes.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43926
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43926&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43926&report=yes
Search -- http://master.php.net/manage/user-notes.php