Posted by Mike Zhang on 12/17/85 11:55
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($matches[1] as $link)
{
echo "<li>$link</li>\n";
}
?>
[Back to original message]
|