Thread: ZipThings
View Single Post
Old 02-02-2009, 11:58 PM   #6 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I can't actually test this script I've just written because my web-server is currently broken, but hopefully it will give you an idea how to go about it If you require any help what-so-ever though, do just ask the community!

php Code:
function getElementsByExtension(array $aExtensions)
{
    $szContent = file_get_contents('http://www.talkphp.com/show-off/3929-zipthings.html');
    $aElements = array();
   
    foreach ($aExtensions as $szExtension)
    {
        preg_match_all('~(?:src|href)="([^"]+\.' . $szExtension . ')"~is', $szContent, $aMatches);
        $aElements[] = $aMatches[1];
    }
   
    $pArray = (object) array('aFlat' => array());
    array_walk_recursive($aElements, create_function('&$v, $k, &$t', '$t->aFlat[] = $v;'), $pArray);
    return $pArray->aFlat;
   
}

print_r(getElementsByExtension(array('jpg', 'gif', 'css')));
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote