note 102221 added to function.strip-tags

From: Date: Thu, 03 Feb 2011 07:44:27 +0000
Subject: note 102221 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-176616@lists.php.net to get a copy of this message
As noted in the documentation strip_tags would strip php and comments tags even if they are add to $allowable_tags. Here is a little workaround for this issue: <?php function stripTags($text, $tags) { // replace php and comments tags so they do not get stripped $text = preg_replace("@<\?@", "#?#", $text); $text = preg_replace("@<!--@", "#!--#", $text); // strip tags normally $text = strip_tags($text, $tags); // return php and comments tags to their origial form $text = preg_replace("@#\?#@", "<?", $text); $text = preg_replace("@#!--#@", "<!--", $text); return $text; } ?> The function would replace the tags to hashes so strip_tags would not identify them as normal tags, and then when strip_tags does its job the tags are modified back to their original form. ---- Server IP: 69.147.83.197 Probable Submitter: 115.64.161.130 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/102221 Del: integrated -- https://master.php.net/note/delete/102221/integrated Del: useless -- https://master.php.net/note/delete/102221/useless Del: bad code -- https://master.php.net/note/delete/102221/bad+code Del: spam -- https://master.php.net/note/delete/102221/spam Del: non-english -- https://master.php.net/note/delete/102221/non-english Del: in docs -- https://master.php.net/note/delete/102221/in+docs Del: other reasons-- https://master.php.net/note/delete/102221 Reject -- https://master.php.net/note/reject/102221 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#176616) next »