note 55695 deleted from function.strip-tags by aharvey

From: Date: Thu, 20 Sep 2012 11:52:32 +0000
Subject: note 55695 deleted from function.strip-tags by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190909@lists.php.net to get a copy of this message
Note Submitter: ---- <?php /**removes specifed tags from the text where each tag requires a *closing tag and if the later *is not found then everything after will be removed *typical usage: *some html text, array('script','body','html') - all lower case*/ public static function removeTags($text,$tags_array){ $length = strlen($text); $pos =0; $tags_array = $array_flip($tags_array); while ($pos < $length && ($pos = strpos($text,'<',$pos)) !== false){ $dlm_pos = strpos($text,' ',$pos); $dlm2_pos = strpos($text,'>',$pos); if ($dlm_pos > $dlm2_pos)$dlm_pos=$dlm2_pos; $which_tag = strtolower(substr($text,$pos+1,$dlm_pos-($pos+1))); $tag_length = strlen($srch_tag); if (!isset($tags_array[$which_tag])){ //if no tag matches found ++$pos; continue; } //find the end $sec_tag = '</'.$which_tag.'>'; $sec_pos = stripos($text,$sec_tag,$pos+$tag_length); //remove everything after if end of the tag not found if ($sec_pos === false) $sec_pos = $length-strlen($sec_tag); $rmv_length = $sec_pos-$pos+strlen($sec_tag); $text = substr_replace($text,'',$pos,$rmv_length); //update length $length = $length - $rmv_length; $pos++; } return $text; } ?>

« previous php.notes (#190909) next »