Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Function to get all links on a certain url using the DomDocument
- Source: http://www.binarytides.com/php-get-links-on-a-page-with-domdocument/
- */
- function get_links($link)
- {
- //return array
- $ret = array();
- /*** a new dom object ***/
- $dom = new domDocument;
- /*** get the HTML (suppress errors) ***/
- @$dom->loadHTML(file_get_contents($link));
- /*** remove silly white space ***/
- $dom->preserveWhiteSpace = false;
- /*** get the links from the HTML ***/
- $links = $dom->getElementsByTagName('a');
- /*** loop over the links ***/
- foreach ($links as $tag)
- {
- $ret[$tag->getAttribute('href')] = $tag->childNodes->item(0)->nodeValue;
- }
- return $ret;
- }
- //Link to open and search for links
- $link = "http://junookyo.blogspot.com/";
- /*** get the links ***/
- $urls = get_links($link);
- /*** check for results ***/
- if(sizeof($urls) > 0)
- {
- foreach($urls as $key=>$value)
- {
- echo $key . ' - '. $value . '<br >';
- }
- }
- else
- {
- echo "No links found at $link";
- }
Add Comment
Please, Sign In to add comment