Click to See Complete Forum and Search --> : cleaning $_POST from html tags
stephan.gerlach
11-20-2006, 05:18 AM
By default i want all $_POST variables to be cleaned from any html tag.
There should be one exception the array $_POST['allow_html'] holds an array of field names which should not be cleaned.
I am really stuck. Any help?? Cheers
pcthug
11-20-2006, 05:26 AM
I'm not exactly sure if I understood...
foreach($_POST as $key => $value)
if(!in_array($key, $_POST['allow_html']) && $key != 'allow_html')
unset($_POST[$key]);
stephan.gerlach
11-20-2006, 06:05 AM
thanks that helped.
this is the code that i was after
if (!isset($_POST['allow_html'])) {
$_POST['allow_html']=array();
}
foreach($_POST as $key => $value) {
if(!in_array($key, $_POST['allow_html']) && $key != 'allow_html' ) {
if (is_array($_POST[$key])) {
foreach($_POST[$key] as $key_1 => $value_1) {
if(!in_array($key_1, $_POST['allow_html']) && $key != 'allow_html' ) {
if (is_array($_POST[$key][$key_1])) {
foreach($_POST[$key][$key_1] as $key_2 => $value_2) {
if(!in_array($key_2, $_POST['allow_html']) && $key != 'allow_html') {
if (is_array($_POST[$key][$key_1][$key_2])) {
echo 'ERROR: POSTCLEAN ONLY SUPPORTS 3 LEVELS OF ARRAYS';
}
else {
$_POST[$key][$key_1][$key_2]=strip_tags($value_2);
}
}
}
}
else {
$_POST[$key][$key_1]=strip_tags($value_1);
}
}
}
}
else {
$_POST[$key]=strip_tags($value);
}
}
}
is there anyway to make it nicer. I tried it with recursion but failed.
Litewebsite
11-20-2006, 07:09 AM
Edit: Sorry, saw that you already used this function...
I think the function strip_tags() (http://www.php.net/strip_tags) could help you with simple "html cleaning".