note 60058 deleted from function.strpos by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Aug 2011 13:18:20 +0000 |
| Subject: | note 60058 deleted from function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182164@lists.php.net to get a copy of this message | ||
Note Submitter: samuraj at xmail dot cz
----
there was a code (from wodzuY2k at interia dot pl) removing all between <script> tags..
but it didn't work if the tag begins like <SCRIPT language=javascript
type=text/javascript>
here is function removing all between "<script" and "/script>"
<?php
function remove_js($contents)
{
while(true)
{
$begPos = strpos($contents,"<script");
if ($begPos===false) break; //all tags were found & replaced.
$endPos = strpos($contents,"/script>",$begPos+strlen("<script"));
$tmp = substr($contents,0,$begPos);
$tmp .= substr($contents,$endPos+strlen("script>"));
$contents = $tmp;
if ($loopcontrol++>100) break; //loop infinity control
continue; //search again
}
return $contents;
}
?>