note 38425 deleted from function.addslashes by philip
| From: | philip@php.net | Date: | Tue, 20 Jul 2004 17:13:15 +0000 |
| Subject: | note 38425 deleted from function.addslashes by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73706@lists.php.net to get a copy of this message | ||
Note Submitter: Luca (quumpe@tin.it)
----
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); }
}
}