note 44800 deleted from function.strip-tags by danbrown

From: Date: Fri, 23 Sep 2011 16:05:33 +0000
Subject: note 44800 deleted from function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183384@lists.php.net to get a copy of this message
Note Submitter: Isaac Schlueter php at isaacschlueter dot com ---- steven --at-- acko --dot-- net pointed out that you can't make strip_slashes allow comments. With this function, you can. Just pass <!--> as one of the allowed tags. Easy as pie: just pull them out, strip, and then put them back. <?php function strip_tags_c($string, $allowed_tags = '') { $allow_comments = ( strpos($allowed_tags, '<!-->') !== false ); if( $allow_comments ) { $string = str_replace(array('<!--', '-->'), array('&lt;!--', '--&gt;'), $string); $allowed_tags = str_replace('<!-->', '', $allowed_tags); } $string = strip_tags( $string, $allowed_tags ); if( $allow_comments ) $string = str_replace(array('&lt;!--', '--&gt;'), array('<!--', '-->'), $string); return $string; } ?>

« previous php.notes (#183384) next »