Regular Expression Problem

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

    #1

    Regular Expression Problem

    I got stuck with regular expression problem.
    What i want to do is to extract hello world if 'message' is found in the
    same row.
    I have gotten until //A. but somehow //B doesn't work.

    <?php
    $string = '<html>
    <body>
    <table>
    <tr>
    <td class="bg-grey-m">
    <table cellpadding="12 ">
    <tr><td>message </td><td><i>hello world</i></td></tr>
    <tr><td>tel</td><td><i>111-111-555</i></td></tr>
    </table>
    </td>
    </tr>
    </table>
    </body>';
    //A
    //preg_match_all( "/<td [^>]*class=\"bg-grey-m\">[^<]+<table([^>]*)>/iU",
    $string, $matches);

    //B
    preg_match_all( "/<td
    [^>]*class=\"bg-grey-m\">[^<]+<table[^>]*>.*message.*<i >(.*)<\/i>.*<\/table>
    ..*/iU", $string, $matches);

    foreach($matche s[1] as $link)
    {
    echo "<li>$link</li>\n";
    }


    ?>



Working...