note 87562 deleted from function.htmlspecialchars by danbrown
| From: | danbrown@php.net | Date: | Wed, 19 May 2010 18:55:43 +0000 |
| Subject: | note 87562 deleted from function.htmlspecialchars by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169423@lists.php.net to get a copy of this message | ||
Note Submitter: nessthehero at gmail dot com
----
Here's a simple function I wrote for parsing form data.
It checks if it's an array and it is recursive (it calls itself).
It also decodes things that have already been encoded so it doesn't change & to
&
<?php
function formspecialchars($var)
{
if (is_array($var)) {
$out = array();
foreach ($var as $key => $v) {
$out[$key] = formspecialchars($v);
}
} else {
$out = htmlspecialchars_decode($var);
$out = htmlspecialchars(stripslashes(trim($out)), ENT_QUOTES);
}
return $out;
}
?>
I encourage people to improve upon this for other purposes! All I use it for is cleaning up form
data, hence the name of the function.