View Full Version : regexp/preg replace

11-24-2006, 05: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,

some js codes
some content here, this should be omited
another js codes

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?

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