<?php 

header
("content-type: text/html; charset=utf-8");

// Použití
echo lidovkyTable('http://vysledky.lidovky.cz/fotbal/fotbal_soutez.php?stat=%C8esko&vek=mu%9Ei&typ=mistrovsk%E1_sout%EC%9E&pozice1=4&id_session=');







function 
lidovkyTable($url ''$ttl 3600)
{
    
// vychozi priznak
    
$cached true;
    
    
// nenalezen soubor nebo probehl expiraci
    
if (!is_file("./cache/" md5($url)) || time() -  filemtime("./cache/" md5($url)) > $ttl)
        
$cached false;
            
    
// neni kesovano
    
if (!$cached)
    {   
        
// debug
        //echo "znovu parsujeme tabulku - " . date('d.m.Y H:i:s');
        
        
$f        file_get_contents($url);
        
$f        iconv("windows-1250""UTF-8"$f);
        if (!
$f)
        {
            echo 
'Nelze načíst - ' $url ;
            return;
        }
        

        
preg_match("~<h2>Tabulka</h2>(.+)<\/table>~Usi"$f$out);

        
//$out[1] = preg_replace("/\<a(.*)\>(.*)\<\/a\>/iU", "$2", $out[1]); // odstrani odkazy
        
$out[1] = preg_replace("~<div(.*)>(.*)<\/div>~iUs""$2"$out[1]); 
        
$out[1] = str_replace("</div>"""$out[1]);
        
$out[1] = preg_replace_callback("/\<a(.*)\>(.*)\<\/a\>/iU""replaceTeamLinks"$out[1]);
        
       
        
// ulozime
        
file_put_contents("./cache/".md5($url), $out[1]);
    }

        
// nacteme tabulku
        
$table file_get_contents("./cache/".md5($url));
        
        return 
$table;
    
}


function 
replaceTeamLinks($in)
{
    
//print_R($in);
    
if (strpos($in[1], 'id_klub') !== FALSE)
    {
        return 
$in[2];
    }
    
    return 
$in[0];
}
?>