PHP RegEx and HTML Table Question

Discussion in 'PHP' started by ip076, Sep 29, 2006.

  1. #1
    I've got an HTML Table:

    
    <table>
    <tr class="table-header">
    <td>Header 1</td>
    <td>Header 2</td>
    </tr>
    <tr class="table-content">
    <td>Data Content 1</td>
    <td>Data Content 2</td>
    </tr>
    <!-- This table-content row repeats multiple times depending on records returned -->
    </table>
    
    HTML:
    Now, what I'm trying to do is use preg_match_all to return all the rows that start with "<tr class="table-content">" and place each row into an array.

    I'm having some trouble coming up with the RegEx Pattern, anyone think them might be able to help out. I've been able to match the starting string using "<tr class="table-content"> as the regex pattern, but I'm getting a bit confused on how to match the whole row. The characters between the opening <tr> and closing </tr> tag can be anything.
     
    ip076, Sep 29, 2006 IP
  2. t.m

    t.m Peon

    Messages:
    108
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    preg_match_all("/<tr class=\"table-content\">(.*?)<\/tr>/si", $html, $table_content, PREG_PATTERN_ORDER);
    
    PHP:
    Assuming the HTML is $html, the above should work.. $table_content will be the array. (The array values will still have HTML in them).
     
    t.m, Sep 29, 2006 IP
    ip076 likes this.
  3. ip076

    ip076 Peon

    Messages:
    79
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey, thanks a bunch for your help!
     
    ip076, Sep 29, 2006 IP