note 38425 added to function.addslashes
| From: | (quumpe@tin.it) | Date: | Sat, 20 Dec 2003 09:03:28 +0000 |
| Subject: | note 38425 added to function.addslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62263@lists.php.net to get a copy of this message | ||
When i got bored to write $_POST[foo] to retrieve variables from previous pages, i wrote this. Since
i've been thinking of including it in each page, it includes a control to avoid re-encoding of
previously encoded variables by renaming them (example: at first encoding, the single quote becomes
\' but without that control in the next page it would became \\' and so on).
As you can see below, for sure i'm not the greatest coder on earth: any further suggestion or
correction is absolutely welcome.
function enc($field)
{
$field = trim($field);
$field = str_replace(" ", "_", $field);
$field = addslashes($field);
return $field;
}
function enc_hidden($field)
{
$field = str_replace("'", "\'", $field);
return $field;
}
foreach($_POST as $i => $value)
{
if(substr($i, 0, 2) != "v_")
{
if(substr($i, 0, 4) == "hid_")
{
$i = str_replace("hid_", "", $i);
$v_{$i} = enc_hidden($value);
}
else
{ $v_{$i} = enc($value); }
}
}
----
Manual Page -- http://www.php.net/manual/en/function.addslashes.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38425
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38425&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38425&report=yes
Search -- http://master.php.net/manage/user-notes.php