PhpRiot
Recent Code Pastes

Listing 1610

Submitted by phpro.org, 4 October 2008
<?php
    function getLinks($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('img');
 
        /*** loop over the links ***/
        foreach ($links as $tag)
        {
            $ret[$tag->getAttribute('title')] = $tag->childNodes->item(0)->nodeValue;
        }
 
        return $ret;
    }
 
   /*** a link to search ***/
    $link = "http://www.cineworld.ie/reservation/ChoixResa.jgi?CINEMA=61";
 
    /*** get the links ***/
    $urls = getLinks($link);
 
    /*** check for results ***/
    if(sizeof($urls) > 0)
    {
        foreach($urls as $key=>$value)
        {
            echo $key . ' - '. $value . '<br >';
        }
    }
    else
    {
        echo "No links found at $link";
    }
?>
Submit a Follow Up