PHP Inform

PHP Information & Web Hosting
 

PHP function to strip html tags atributes

function strip_tags_attributes($string, $allowtags=NULL,$ allowattributes=NULL){ 
$string = strip_tags($string,$allowtags) ; 
if (!is_null($allowattributes)) { 
if(!is_array($allowattributes) ) 
$allowattributes = explode(”,”,$allowattributes);
if(is_array($allowattributes))
$allowattributes = implode(”)(? if (strlen($allowattributes) > 0) 
$allowattributes = “(? $string = preg_replace_callback("/<[^>]* >/i”,create_function( 
‘$matches', 
‘return preg_replace(”/ [^ =]*'.$allowattributes.'=(\”[^\ "]*\”|\'[^\']*\')/i”, “”, $matches[0]);' 
),$string); 

return $string; 
}