Skip to content

Instantly share code, notes, and snippets.

@ThomasWeinert
Forked from tliff/gist:4500652
Last active December 10, 2015 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasWeinert/4500763 to your computer and use it in GitHub Desktop.
Save ThomasWeinert/4500763 to your computer and use it in GitHub Desktop.
<?php
$data = '<div>blabla<h1><a href="http://www.example.com/blabla.php?id=12345" class=l>blub</a></h1><h2><a href="http://www.example.com/asfadfafadf.php?id=12345" class=l>blub</a></h2>sdfafgdghaghagh<h1><a href="http://www.example.com/fdgadfhfh.php?id=123dsfasdf45" class=l>blub</a>asdfasdfasdf</h1>';
$doc = new DOMDocument();
$doc->loadHTML($data);
$xpath = new DOMXpath($doc);
$linkTargets = array();
foreach ($xpath->evaluate('//*[@href]/@href', NULL, FALSE) as $attribute) {
$linkTargets[] = $attribute->value;
}
print_r($linkTargets);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment