note 89654 added to function.strip-tags

From: Date: Wed, 18 Mar 2009 10:08:17 +0000
Subject: note 89654 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-152072@lists.php.net to get a copy of this message
Function to strip tags and attributes, but with allowable attributes 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); } $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); } Usage: Allowable attributes can be comma seperated or array Example: strip_tags_attributes($string,'<strong><em><a>','href,rel'); ---- Server IP: 92.48.74.199 Probable Submitter: 82.33.205.169 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/89654 Del: integrated -- https://master.php.net/note/delete/89654/integrated Del: useless -- https://master.php.net/note/delete/89654/useless Del: bad code -- https://master.php.net/note/delete/89654/bad+code Del: spam -- https://master.php.net/note/delete/89654/spam Del: non-english -- https://master.php.net/note/delete/89654/non-english Del: in docs -- https://master.php.net/note/delete/89654/in+docs Del: other reasons-- https://master.php.net/note/delete/89654 Reject -- https://master.php.net/note/reject/89654 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152072) next »