<?php
function get_urls($string, $strict=true) 
{
  $type = "href";
  $innerT = $strict?'[a-z0-9:?=&@/._-]+?':'.+?';
  preg_match_all ("|$type\=([\"'`])(".$innerT.")\\1|i", $string, $matches);
  $ret[$type] = $matches[2];
  return $ret;
}


$bestand = fopen ("http://www.apple.com/trailers", "r");
if (!$bestand) {
   echo "<p>Error met openen van bestand.</p>\n";
   exit;
}

while (!feof ($bestand)) {
   $output = fgets($bestand, 131072); //max 128kbyte inlezen

   $urls = get_urls($output, true);

   $max = count($urls['href']);

   for ($i = 0; $i < $max; $i++)
   {
     if($urls['href'][$i])
     {
       preg_match("/trailers.*/", $urls['href'][$i], $matches);
       if (isset($matches[0]))
       {
         $fullurl = "http://www.apple.com/".$matches[0];
         echo "<a href=\"";
         echo $fullurl;
         echo "\">";
         echo $matches[0];
         echo "</a>";
         echo "<br>\n";
       }
     }
   }
}
fclose($bestand);

//$host = $matches[2];
?>