SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Whistler, Canada
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_match_all: Unknown modifier ']'

    Hi all,

    I've been working on this regex, and in both Regulator and Zend Studio it works fine.

    Code:
    <table.+class\b\s*=\s*[\"\']?\btabl\b[\"\'][^>]*>(.*?)</table>
    However, the next step is giving me the trouble. Here's what I put in my PHP:

    PHP Code:
    preg_match_all("<table.+class\b\s*=\s*[\"\']?\btabl\b[\"\'][^>]*>(.*?)</table>"$html$matches); 
    Running the script results in this error:
    Code:
     Warning: preg_match_all() [function.preg-match-all]: Unknown modifier ']' in /mysite/myfile.php
    
    My goal is to strip the part that matches this regex from the $html ($html contains a CURL post result).
    Anyone who can help me out here?

    Thanks in advance,
    Pepe
    ps: pointers to improve my regex are most welcome!

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Whistler, Canada
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind

    This fixed it:
    PHP Code:
    preg_match_all("/<table.+class\b\s*=\s*[\"\']?\btabl\b[\"\'][^>]*>(.*?)<\/table>/i"$html$matches); 

  3. #3
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have forgotten to put delimiters around your regex:

    PHP Code:
    preg_match_all("~<table.+class\b\s*=\s*[\"\']?\btabl\b[\"\'][^>]*>(.*?)</table>~"$html$matches); 
    ps: pointer
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Whistler, Canada
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome, thanks.


Bookmarks

Posting Permissions

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