<?php 

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

// Použití
echo showSoccerTable('http://nv.fotbal.cz/domaci-souteze/druha-liga/dalsi-info/souteze.asp?soutez=001A2A&show=Tabulka');








/**
 * showSoccerTable()
 * 
 * Funkce umoznuje parsovat fotbalove tabulky ze serveru SPORT
 * 
 * @date 12-06-2008
 * @author Roman Janko <admin@rjwebdesign.net>     
 * @param string $url  nacitame konkretni tabulku ze serveru SPORT
 * @param integer $ttl  nastavujeme dobu expirace stahovani, defaultne 3600 (1 hodina)
 * @return string
 *  
 */
function showSoccerTable($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("ISO-8859-2""UTF-8"$f);
        if (!
$f)
        {
            echo 
'Nelze načíst - ' $url ;
            return;
        }
        
        
$table    preg_match("~TABULKA</td></tr>(.+?)</table>~s"$f$out);
        
$ourTable '<table border="1">' strip_tags($out[1], "<td>,<tr>,<table>,<th>") . '</table>';
        
        
$ourTable str_replace(array(' bgcolor="#aaaaaa"'' bgcolor="#aaaaaa"'' bgcolor="#f8f8f8"'' bgcolor="#ffffff"'), array(''), $ourTable);
    
        
// ulozime
        
file_put_contents("./cache/".md5($url), $ourTable);
    }

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