Code Snippet
Find All Links on a Page
Here's the basic principal behind spiders.
$html = file_get_contents('http://www.example.com');
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
echo $url.'<br />';
}
Exactly what I needed. Thanks.
Perfect for affiliate sites!
WAAAAO ITS GREAT….I WAS SEARCHING FOR THIS ONLY
I didnt understand quite how to use this? where to I type that? I’m kinda confused.. I need more explanation
Thanks
This post is just too good. thumbs up!!
keep up the good work ;)
Muchas gracias por la ayuda!
Works perfect! thx!
Can someone please show me step by step in how to use this. Thank you in advance
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.