sim.plified.com

Chris Pollock

Chris Pollock - web developer (PHP/mySQL & ASP.NET)
undivided… my thoughts on world, family, church, business, technology and Jesus Christ (all in all)

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”

Things I see

Amy and baby after storm cloud bike rideRochester storm cloudHuge storm cloud Rochester NYSad life preserver SimonHappy life preserver SimonFuture employee?Simon rides jasmineMicah with ear protectionMicah with ear protectionCIMG7660100_3672100_3666100_3661100_3650100_3643

Chris Pollock

Web Developer - proficient in both PHP and ASP.NET.
Rochester, New York

View my web developement site.

View Chris Pollock's LinkedIn profile

My Pictures

Amy and baby after storm cloud bike rideRochester storm cloudHuge storm cloud Rochester NYSad life preserver SimonHappy life preserver SimonFuture employee?Simon rides jasmineMicah with ear protectionMicah with ear protectionCIMG7660100_3672100_3666100_3661100_3650100_3643