note 33826 added to function.strip-tags
| From: | jimi at psu dot edu | Date: | Tue, 08 Jul 2003 20:12:02 +0000 |
| Subject: | note 33826 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51728@lists.php.net to get a copy of this message | ||
To eminate the script tags found in html, don't use the preg_replace approach. The .* can
include </script> when there are multiple script tags, and you could be replacing content
other than the script tag.
The following function will find the begining and ending character occurance on the script tag, crop
the html, then repeat the process until all tags are removed.
function strip_tag_script($html) {
$pos1 = false;
$pos2 = false;
do {
if ($pos1 !== false && $pos2 !== false) {
$first = NULL;
$second = NULL;
if ($pos1 > 0)
$first = substr($html, 0, $pos1);
if ($pos2 < strlen($html) - 1)
$second = substr($html, $pos2 + 1);
$html = $first . $second;
}
preg_match("/<script[^>]*>/i", $html, $matches);
$str1 =& $matches[0];
preg_match("/<\/script>/i", $html, $matches);
$str2 =& $matches[0];
$pos1 = strpos($html, $str1);
$pos2 = strpos($html, $str2);
if ($pos2 !== false)
$pos2 += strlen($str2);
} while ($pos1 !== false && $pos2 !== false);
return $html;
}
----
Manual Page -- http://www.php.net/manual/en/function.strip-tags.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33826
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33826&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33826&report=yes