note 33826 deleted from function.strip-tags by vrana
| From: | vrana@php.net | Date: | Mon, 22 Dec 2003 16:32:55 +0000 |
| Subject: | note 33826 deleted from function.strip-tags by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62342@lists.php.net to get a copy of this message | ||
Note Submitter: jimi@psu.edu
----
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);
$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;
}