Posted by mich dobelman on 10/27/25 11:55
I am trying to extract hello world out of the following html string if
the "message" string is found in the same row.
I am not sure why it's not working.
<?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>';
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";
}
?>
Navigation:
[Reply to this message]
|