Any idea what's wrong with this code snippet?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GeoffreyF67

    #1

    Any idea what's wrong with this code snippet?

    <?

    $pattern = "<script[^>]*?>.*?</script>";
    $replacement = "";
    $subject = " <Description><s cript
    src='http://x.com/rd/j/rf.jsp?pD=41422 '></script>Official site. Enjoy
    lower rates in the heart of Montreal at the

    Fairmont Queen Elizabeth. Save 10% if you book 3 weeks in advance. From
    $199 CAD per night. Fairmont, Creating Memories.</Description>";

    $test = preg_replace($p attern,$replace ment,$subject);

    echo $test;
    ?>

    Generates:

    Warning: preg_replace(): Unknown modifier ']' in
    /web/sites/kerryc/buyers-source-online.com/testme.php on line 9

    I just wanna replace the <script tag with nothing...it can't be THAT
    hard :)

    G-Man

  • petersprc@gmail.com

    #2
    Re: Any idea what's wrong with this code snippet?

    The first character of the pattern is considered the delimiter
    character. Try something like:

    $pattern = '#<\s*script\s+ .*?>.*?<\s*/\s*script>#is';

    The delimiter character (#) separates the regular expression from the
    pattern modifiers.

    You might be interested in PEAR::HTML_Safe , which sanitizes HTML.

    Best Regards,

    John Peters

    GeoffreyF67 wrote:
    <?
    >
    $pattern = "<script[^>]*?>.*?</script>";
    $replacement = "";
    $subject = " <Description><s cript
    src='http://x.com/rd/j/rf.jsp?pD=41422 '></script>Official site. Enjoy
    lower rates in the heart of Montreal at the
    >
    Fairmont Queen Elizabeth. Save 10% if you book 3 weeks in advance. From
    $199 CAD per night. Fairmont, Creating Memories.</Description>";
    >
    $test = preg_replace($p attern,$replace ment,$subject);
    >
    echo $test;
    ?>
    >
    Generates:
    >
    Warning: preg_replace(): Unknown modifier ']' in
    /web/sites/kerryc/buyers-source-online.com/testme.php on line 9
    >
    I just wanna replace the <script tag with nothing...it can't be THAT
    hard :)
    >
    G-Man

    Comment

    • GeoffreyF67

      #3
      Re: Any idea what's wrong with this code snippet?

      Thanks! That's very helpful!

      G-Man

      Comment

      Working...