note 97991 added to function.htmlspecialchars
| From: | nessthehero at gmail dot com | Date: | Wed, 19 May 2010 18:53:04 +0000 |
| Subject: | note 97991 added to function.htmlspecialchars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169420@lists.php.net to get a copy of this message | ||
Updated my form data parser. I found it easier to use a regular expression to check and see if any
previously encoded data exists, then decode it repeatedly until there is none left, then re-encode
it.
<?php
function formspecialchars($var)
{
$pattern = '/&(#)?[a-zA-Z0-9]{0,};/';
if (is_array($var)) { // If variable is an array
$out = array(); // Set output as an array
foreach ($var as $key => $v) {
$out[$key] = formspecialchars($v); // Run formspecialchars on every element of the array and
return the result. Also maintains the keys.
}
} else {
$out = $var;
while (preg_match($pattern,$out) > 0) {
$out = htmlspecialchars_decode($out,ENT_QUOTES);
}
$out = htmlspecialchars(stripslashes(trim($out)), ENT_QUOTES,'UTF-8',true); // Trim
the variable, strip all slashes, and encode it
}
return $out;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 158.83.184.98
----
Manual Page -- http://www.php.net/manual/en/function.htmlspecialchars.php
Edit -- https://master.php.net/note/edit/97991
Del: integrated -- https://master.php.net/note/delete/97991/integrated
Del: useless -- https://master.php.net/note/delete/97991/useless
Del: bad code -- https://master.php.net/note/delete/97991/bad+code
Del: spam -- https://master.php.net/note/delete/97991/spam
Del: non-english -- https://master.php.net/note/delete/97991/non-english
Del: in docs -- https://master.php.net/note/delete/97991/in+docs
Del: other reasons-- https://master.php.net/note/delete/97991
Reject -- https://master.php.net/note/reject/97991
Search -- https://master.php.net/manage/user-notes.php