PHP Inform

PHP Information & Web Hosting
 

PHP function that strips both – tags and atributes

function strip_tags_attributes($string, $allowtags=NULL,$ allowattributes=NULL){ 
if($allowattributes){ 
if(!is_array($allowattributes) ) 
$allowattributes = explode(”,”,$allowattributes);
if(is_array($allowattributes))
$allowattributes = implode(”|”,$allowattributes);
$rep = ‘/([^>]*) ('.$allowattributes.')(=)(\'.* \'|”.*”)/i'; 
$string = preg_replace($rep, ‘$1 $2_-_-$4', $string); 

if(preg_match('/([^>]*) (.*)(=\'.*\'|=”.*”)(.*)/i',$ string) > 0){ 
$string = preg_replace('/([^>]*) (.*)(=\'.*\'|=”.*”)(.*)/i', ‘$1$4', $string); 

$rep = ‘/([^>]*) ('.$allowattributes.')(_-_-)(\ '.*\'|”.*”)/i'; 
if($allowattributes) 
$string = preg_replace($rep, ‘$1 $2=$4', $string); 
return strip_tags($string,$allowtags) ; 
}