note 102221 deleted from function.strip-tags by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 12:18:18 +0000 |
| Subject: | note 102221 deleted from function.strip-tags by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197163@lists.php.net to get a copy of this message | ||
Note Submitter: Abdul Al-hasany
----
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.