Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Location
    Nigeria
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regexp/preg replace

    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
    Code:
    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,
    Code:
    <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...
    Code:
    preg_replace("/<script[^>]*?>[^(<\/script>)]*</script*>/is", "", $content);
    any ideas?

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Use this regex instead:
    Code:
    /<script[^>]*?>.*?</script>/is
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •