<?php
// config

$bestand = downloadFile("http://sexmaxx.com/");
$invoer = array("www.kharkovsex.com", "www.xxxteensparty.com", "xxxteensparty.com", "www.thumbsman.com", 
                "www.steamy-girls.com", "www.500galleries.com", "www.britishcoeds.com", "britishcoeds.com",
                "www.angel-funs.com", "www.fineartbeauties.com", "www.x-gallery.com", "www.wild-teenz.com",
                "www.innocent-beauty.com");


function get_urls($string, $strict=true) 
{
   $types = array("href");
   while(list(,$type) = each($types)) {
       $innerT = $strict?'[a-z0-9:?=&@/._-]+?':'.+?';
       preg_match_all ("|$type\=([\"'`])(".$innerT.")\\1|i", $string, $matches);
       $ret[$type] = $matches[2];
   }
   return $ret;
}

function downloadFile($url) {
  $bestand = fopen ($url, "r");
  if (!$bestand) {
    echo "<p>Error met downloaden van file.</p>\n";
    exit;
  }
  return $bestand;
}

function verwerk($file, $invoer)
{
  while (!feof ($file)) 
  {
    $line = fgets($file, 10240);
    $urls = get_urls($line, true);
    $maxurls = count($urls['href']);
    for ($i = 0; $i < $maxurls; $i++)
    {
      if($urls['href'][$i])
      {
        $maxinvoer = count($invoer);
        for ($k = 0; $k < $maxinvoer; $k++)
        {
          preg_match("/".$invoer[$k]."?[^ ][^<]+/i", $urls['href'][$i], $matches);
          if(!empty($matches[0]))
          {
            $uitvoer[$invoer[$k]][] = $matches[0];
          }
        }
      }
    }
  }
  fclose($file);
  return $uitvoer;
}

function display($titel, $gegevens)
{
  $output = "<h1>".$titel."</h1>\n";

  $max = count($gegevens);
  for ($i = 0; $i < $max; $i++)
  {
    $output.= "<a target=\"_blank\" href=\"http://";
    $output.= $gegevens[$i];
    $output.= "\">";
    $output.= "http://".$gegevens[$i];
    $output.= "</a><br>\n";
  }
  return $output;
}

// uitvoeren/verwerken

$data = verwerk($bestand, $invoer);

$max = count($invoer);
for ($i = 0; $i < $max; $i++)
{
  if(!empty($data[$invoer[$i]]))
  {
    echo display($invoer[$i],$data[$invoer[$i]]);
  }
}

?>
