sim.plified.com

Chris Pollock

Chris Pollock - web developer & ecommerce entrepreneur
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”

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Things I see

IMG_7347BookFinally!Little peanutTime to set sailEyes openSleepy TimeAri Jeremiah PollockBig brotherBaby's HomeBike manBiker gangBirthday monopoly.$5 StarIMG_2881

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

IMG_7347BookFinally!Little peanutTime to set sailEyes openSleepy TimeAri Jeremiah PollockBig brotherBaby's HomeBike manBiker gangBirthday monopoly.$5 StarIMG_2881