SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can't figure out a simple regular expression

    Given a HTML file, I'm looking for a regex that can give me the text that matches the following:

    <table width="132" border="0" cellpadding="0" cellspacing="0">

    ANYTHING

    </table>

    I've tried the following:

    /<table width=\"132\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">(.*?)<\/table>/

    But it doesn't work, I'm not sure how to fix it...
    Work smarter, not harder. -Scrooge McDuck

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    Code:
    #<table width=\"132\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">(.*?)</table>#s

  3. #3
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the regexp is indeed correct. I guess the text between the table tags spans multiple lines? Then you need to use /s for the regexp to match over multiple lines. Normally the regexp matches only one line:

    PHP Code:
    preg_match_all('#<table width="132" border="0" cellpadding="0" cellspacing="0">(.*?)</table>#s'$html$match);

    print_r($match); 
    edit: too slow


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
  •