...

View Full Version : regexp/preg replace



kehers
11-24-2006, 04:02 PM
Im trying to run a preg_replace for replacing some things in the contents of a retrieved webpage. For example, im using the snip below to strip out all javascripts within the content


preg_replace("/<script[^>]*?>.*</script*>/is", "", $content);

The problem with dat however is that, if there happens to be more than 2 script tags within the content, e.g,


<script>
some js codes
</script>
some content here, this should be omited
<script>
another js codes
</script>

the match matches from the begining script to the end script, swallowing allong "some content here". The idea is to simply replace contents within each individual script tags.
I tried using this but didnt work either...


preg_replace("/<script[^>]*?>[^(<\/script>)]*</script*>/is", "", $content);

any ideas?

marek_mar
11-24-2006, 08:00 PM
Use this regex instead:


/<script[^>]*?>.*?</script>/is



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum