never ever use fopen for files outside your webserver. (i know atleast my host and my webserver have the url wrapper turned OFF so you cant even do that anyway)
use the curl library like. (which is way better)
code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$foo = curl_exec($ch);
curl_close($ch);
and $foo will be the downloaded data
and did you even read what preg_match did? the 3rd param is a varible witch will contain the matches , so why not check that then loop through it
and I dont even get why your exploding the url by the regexp?
and your last while is a never ending loop because you never increase $i.
For is alot better for looping than that last while.
http://php.net/for