$url = 'MyUrl';
$contents = file_get_contents($url);
function scrape_between($data, $start, $end){
$data = stristr($data, $start);
$data = substr($data, strlen($start));
$stop = stripos($data, $end);
$data = substr($data, 0, $stop);
return $data;
}
$svetaines_turinys = trim(scrape_between($contents, "<table border=\"0\" cellspacing=\"0\">", "</table>"));
$fp = fopen("autogidas.php", "w+");
fwrite ($fp, "$svetaines_turinys");
fclose ($fp);
$fh = fopen("autogidas.php", 'r') or die("negalima atidaryti");
while(! feof($fh)) {
$visa_data1 = fgets($fh);
$visa_data = trim($visa_data1);
$pavadinimas = trim(scrape_between($visa_data, "<span class=\"ttitle2\">", "</span>"));
$metai = trim(scrape_between($visa_data, "<span class=\"ttitle1\">", "</span>"));
$kaina = trim(scrape_between($visa_data, "<span class=\"ttitle1\" style='float: left;'>", "<br /><span class=\"grey\">"));
echo "$pavadinimas<br> $metai <br> $kaina . <br><br>";
}
fclose($fh);
Output is working fine, but the problem is the output with a lot of free space, I tried to use trim(), but it didn't solved the problem.
Aucun commentaire:
Enregistrer un commentaire