note 87562 added to function.htmlspecialchars
| From: | nessthehero at gmail dot com | Date: | Wed, 10 Dec 2008 16:28:07 +0000 |
| Subject: | note 87562 added to function.htmlspecialchars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147999@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 64.71.164.2
Probable Submitter: 158.83.184.42
----
Manual Page -- http://www.php.net/manual/en/function.htmlspecialchars.php
Edit -- https://master.php.net/note/edit/87562
Del: integrated -- https://master.php.net/note/delete/87562/integrated
Del: useless -- https://master.php.net/note/delete/87562/useless
Del: bad code -- https://master.php.net/note/delete/87562/bad+code
Del: spam -- https://master.php.net/note/delete/87562/spam
Del: non-english -- https://master.php.net/note/delete/87562/non-english
Del: in docs -- https://master.php.net/note/delete/87562/in+docs
Del: other reasons-- https://master.php.net/note/delete/87562
Reject -- https://master.php.net/note/reject/87562
Search -- https://master.php.net/manage/user-notes.php