Bu yazıda PHP ve RegEx kullanarak Boğaziçi Üniversitesi Kandilli Rasathanesi sayfasından güncel deprem bilgilerini nasıl alabileceğinizi göstericem. Bu yazı bu tarzda vermiş olduğum 3. örnek olacak ve şimdilik bu konu ile ilgili başka örnek yapmayı düşünmüyorum.
setlocale(LC_ALL, 'tr_TR', 'tr', 'turkish');
if(function_exists("date_default_timezone_set")) {
date_default_timezone_set('Europe/Istanbul');
}
function son_depremler($sayi=5) {
$contents=file_get_contents("http://www.koeri.boun.edu.tr/scripts/lst9.asp");
$pattern='/(d{4}).(d{2}).(d{2})s(d{2}):(d{2}):(d{2})s+(d{2}.d{4})s+(d{2}.d{4})s+(d+.d)s+([d.-s]+)(.+)/';
preg_match_all($pattern,$contents,$out);
unset($out[0]);
$depremler=array();
for($i=0; $i<$sayi; $i++) {
$depremler[]=array('timestamp' => mktime($out[4][$i],$out[5][$i],$out[6][$i],$out[2][$i],$out[3][$i],$out[1][$i]), 'enlem' => $out[7][$i], 'boylam' => $out[8][$i], 'derinlik' => $out[9][$i], 'buyukluk' => trim(str_replace("-.-","",$out[10][$i])), 'yer' => trim($out[11][$i]));
}
unset($out);
return $depremler;
}
foreach(son_depremler(3) as $deprem) {
echo strftime("%d %B %Y, %A %H:%M:%S", $deprem[timestamp]);
echo "
<br />
";
echo "Enlem: ".$deprem[enlem];
echo "
<br />
";
echo "Boylam: ".$deprem[boylam];
echo "
<br />
";
echo "Derinlik: ".$deprem[derinlik];
echo "
<br />
";
echo "Büyüklük: ".$deprem[buyukluk];
echo "
<br />
";
echo "Yer: ".$deprem[yer];
echo "
<br />
<br />
";
}