Re: problem with code to strip html characters from all POST data
| From: | Robin Vickery | Date: | Fri, 01 Sep 2000 10:54:59 +0000 |
| Subject: | Re: problem with code to strip html characters from all POST data | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14790@lists.php.net to get a copy of this message | ||
rick.moynihan@mclsoftware.co.uk ("Rick Moynihan") writes:
> Okay, I'm having some problems with the piece of code below. Basically I am
> trying to strip all html tags from all POST variables. I then use
> dynamically assigned variable names to overwrite the 'named variables' php
> creates with my stripped data.
> The code below works fine unless there is an array in the html form. In
> which case it doesn't actually remove the html tags, I assume this is
> because I am actually addressing an array within an array incorrectly.
> Although it appears to make the changes (the testing lines confirm this)
> they don't actually stand.
> I'm sure this is pretty simple stuff - But, I'm somewhat new to php and the
> way it handles arrays seems strange to someone who's background is in more
> traditional C programming.
This is a recursive method of doing it that should be able
to cope with the multi-dimensional arrays that are allowable
in php4.
-robin
<?php
function cleanup( &$value, $key )
{
if (is_array($value)) {
array_walk( $value, "cleanup" );
} else {
$value = strip_tags($value);
}
}
$CLEAN_POST_VARS = $HTTP_POST_VARS;
array_walk( $CLEAN_POST_VARS, "cleanup_tags" );
extract( $CLEAN_POST_VARS, EXTR_OVERWRITE );
?>
--
Robin Vickery...............................................
Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK
Email: robin@planet-three.net Phone: +44 (0)870 729 5444