Jump to content

[SOLVED] matching <h3 class=r><a href="[url]"


daydreamer

Recommended Posts

Alternatively, you could also resort to DOM/XPath for this sort of thing:

 

Example:

$html = <<<EOF
<h3 class=r><a href="[url=http://www.whatever.com]www.whatever.com[/url]">Link</a>
<table><td><tr>blah</tr></td></table>
<h3 class=r><a href="[url=http://www.whatever2.org/somefolder/index.php]www.whatever2.org/somefolder/index.php[/url]">Link 2</a>
EOF;

$dom = new DOMDocument;
@$dom->loadHTML($html); // change loadHTML to loadHTMLFile, and replace $html with the real url encased in quotes
$xpath = new DOMXPath($dom);
$aTag = $xpath->query('//h3[@class="r"]/a');
foreach ($aTag as $val) {
    $arr[] = $val->getAttribute('href');
}

echo '<pre>'.print_r($arr, true);

Link to comment
https://forums.phpfreaks.com/topic/170242-solved-matching/#findComment-898155
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.