note 113545 added to class.domdocument

From: Date: Mon, 28 Oct 2013 14:54:36 +0000
Subject: note 113545 added to class.domdocument
Groups: php.notes 
Request: Send a blank email to php-notes+get-197338@lists.php.net to get a copy of this message
A simple function to grab all links in a page. function get_links($url) { // Create a new DOM Document to hold our webpage structure $xml = new DOMDocument(); // Load the url's contents into the DOM $xml->loadHTMLFile($url); // Empty array to hold all links to return $links = array(); //Loop through each <a> tag in the dom and add it to the link array foreach ($xml->getElementsByTagName('a') as $link) { $url = $link->getAttribute('href'); if (!empty($url)) { $links[] = $link->getAttribute('href'); } } //Return the links return $links; } ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/class.domdocument.php Edit -- https://master.php.net/note/edit/113545 Del: integrated -- https://master.php.net/note/delete/113545/integrated Del: useless -- https://master.php.net/note/delete/113545/useless Del: bad code -- https://master.php.net/note/delete/113545/bad+code Del: spam -- https://master.php.net/note/delete/113545/spam Del: non-english -- https://master.php.net/note/delete/113545/non-english Del: in docs -- https://master.php.net/note/delete/113545/in+docs Del: other reasons-- https://master.php.net/note/delete/113545 Reject -- https://master.php.net/note/reject/113545 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197338) next »