k.<?php
error_reporting
(E_ALL);
define("RE_RESOURCE",'[<a href=\"/resources\">Resources</a> > <a href=\"/resources/view/[0-9]+?\">([a-zA-Z0-9-_]+?)<\/a>]is');
define("RE_NAME",'[wna podmiotu (.+?)    <\/title>]is');
/*function get_url($url,$cache_key){
    $filename = './cache/'.$cache_key;
    if(file_exists($filename)){
        $result = file_get_contents($filename); 
    }else{
        $result = file_get_contents($url);
    };
    return $result;
};*/

function get_url($url,$regexp,$cache_key){
    
$filename './cache/'.$cache_key;
    if(
file_exists($filename)){
        
$result file_get_contents($filename);
    }else{
        
$content file_get_contents($url);
        if(
preg_match($regexp,$content,$matches)){
            
$result $matches[1];
            
file_put_contents($filename,$result);
        
mail('[email protected]',"Nowy podmiot na SSDIP",$url." \n ".$result);
        }else{
            return 
FALSE;
        }
    };
    return 
$result;        
}    
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Wykaz SSDIP</title>
    <!--[if IE]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<body>
<h1>Wykaz instytucji wykorzystujących SSDIP</h1>
<p>SSDIP to aplikacja świadczona przez Ministerstwo Administracji i Cyfryzacji zapewniająca możliwość bezpłatnego utworzenia i prowadzenia Biuletynu Informacji Publicznej przez każdy podmiot zobowiązany na mocy ustawy z dnia 6 września 2001 roku o dostępie do informacji publicznej do tego.</p>

<?php
$id 
13;
$limit 10;
?>
<ol start=13>
<?php
while($limit>0){
    
?><?php
    
if($alias get_url('http://mac.bip.gov.pl/versions/index/Resource/'.$id,RE_RESOURCE,'r_'.$id)){
        
?><li><?php $limit 10;
        
$url 'http://'.$alias.'.bip.gov.pl/';
        if(
$name get_url($url,RE_NAME,'b_'.$alias)){
            echo 
$url.'==><a href="'.$url.'">'.$name.'</a>';
        }else{
            echo 
'<a href="'.$url.'">'.$url.'</a>';
        }
?></li>
<?php
    
}else{
        
$limit--;
    }
    
$id++;
}
?></ol>
<?php echo $id?>
<p>Kod źródłowy PHP niniejszej strony jest <a href="code.php">publiczny</a>.</p>
</body>
</html>