note 96194 deleted from function.strip-tags by danbrown

From: Date: Sat, 13 Feb 2010 14:49:24 +0000
Subject: note 96194 deleted from function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165936@lists.php.net to get a copy of this message
Note Submitter: Matthieu Larcher ---- I found the function given by Mehul to enhance the basic strip_tags very useful. However, it alters the content : we don't necessarily want all non tag-opening "<" to be replaced by "&lt;" Here is a version that will return the exact same content as the input, minus the tags : function enhanced_strip_tags( $content ) { $parts = explode( '<', $content ); $result = $parts[0]; for( $i = 1; $i < count($parts); $i++ ) { if( !strpos( $parts[$i], '>' ) ){ $result = $result . '¤&lt;¤' . $parts[$i]; } else { $result = $result . '<' . $parts[$i]; } } return str_replace( '¤&lt;¤', '<', strip_tags( $result ) ); } Note that I used dummy "¤" characters to avoid the unwanted replacement of "&lt;" that belonged to the content in the first place. The intent here is only to have something unique as a placeholder for non tag-opening "<". This may pose problems if utf-8 is not handled, so feel free to use whatever you want instead.

« previous php.notes (#165936) next »