note 84867 modified in function.htmlentities by felipe
| From: | felipe@php.net | Date: | Fri, 08 Aug 2008 11:13:39 +0000 |
| Subject: | note 84867 modified in function.htmlentities by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143303@lists.php.net to get a copy of this message | ||
This looping function below is useful to disable html in user generated content (message board
posts, webpage-based chat clients, etc). And, so far, it's worked fine alone for sanitizing
user input for database storage. "htmlize_text" here preserves keys and works on
recursive arrays.
<?php
$_GET = htmlize_text($_GET);
$_POST = htmlize_text($_POST);
function htmlizeArray(&$txtArray) {
if (is_array($txtArray)) {
foreach ($txtArray as $key => $val) {
htmlizeArray($val);
}
}
else {
htmlentities($txtArray);
}
}
?>
--was--
This looping function below is useful to disable html in user generated content (message board
posts, webpage-based chat clients, etc). And, so far, it's worked fine alone for sanitizing
user input for database storage. "htmlize_text" here preserves keys and works on
recursive arrays.
<?php
$_GET = htmlize_text($_GET);
$_POST = htmlize_text($_POST);
function htmlize_text($txtarray) {
// return translated txtarray
if (is_array($txtarray)) {
foreach ($txtarray as $key => $val) {
$txtarray[$key] = htmlize_text($val);
}
}
else {
$txtarray = htmlentities(trim($txtarray),ENT_QUOTES);
}
return $txtarray;
}
?>
http://php.net/manual/en/function.htmlentities.php