Created
January 10, 2013 09:09
-
-
Save tliff/4500652 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
$elements = $doc->getElementsByTagName('h1'); | |
$link_targets = array(); | |
foreach ($elements as $element){ | |
foreach($element->childNodes as $child){ | |
if(get_class($child) == 'DOMElement' && $child->hasAttribute("href")){ | |
$link_targets[] = $child->getAttribute("href"); | |
} | |
} | |
} | |
print_r($link_targets); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment