Parsing URLs from Flickr Descriptions
PatternTap had its beginnings in flickr. Instead of transferring all that data by hand, flickr's API allows us to access the data very nicely. Unfortunately, the source URL for each images was not in a separate field, but in the general description field. I wrote the following PHP function to parse the last URL out of the description and return it as a string.
// Returns the last URL in an HTML description // Input: HTML description // Output: URL string function return_url_from_description($desc) { $url = ""; $doc = new DOMDocument(); // shove the description in the dom $doc->loadHTML($desc); // search for anchor tags $a_tags = $doc->getElementsByTagName("a"); for ($i = 0; $i < $a_tags->length; $i++) { // get the href attribute of the anchor tag $url = $a_tags->item($i)->getAttribute("href"); } return $url; }










No Comments, Comment or Ping
Reply to “Parsing URLs from Flickr Descriptions”