<?php

$x = file_get_contents($file);

$final = preg_match("~<tr[^>]*>(.+)</tr>~si", $x, $match);

$lastTr = strpos($match[0], '</tr>');
$match[0] = substr($match[0], $lastTr + 8,  strlen($match[0]));


file_put_contents("frag.txt", $match[0]);

$f = fopen("frag.txt", "r");

$cols = array("kolo", "datum", "cas", "domaci", "hoste", "skore", "strelci_karty");

//$in_td = false;
$rows = array();

while (!feof($f))
{
   $r = fgets($f);
   # preskocit prazdne radky
   if ( trim($r) != '' )
   {
      if (strpos($r, '<tr') !== false)
      {
        // $in_td=true;
         $rows = array();
      }
      else
      {
         if (strpos($r, '</tr') !== false)
         {
            //$in_td = false;
            #zpracuju $rows

            if (count($rows) == 8)
            {
               #mam v prvni bunce kolo
               $kolo = array_shift($rows);
            }
            zapis_insert($kolo, $rows);
            //print_r($rows);

         }
         else
         {
            if (strpos($r, '<td') !== false)
            {
               $t = preg_replace('/<[^>]*>/', '', trim($r));
               $rows[] = $t;
            }
         }
      }
   }
}