Skip to content

Instantly share code, notes, and snippets.

@wutlu
Last active July 21, 2019 14:04
Show Gist options
  • Save wutlu/6267b7b5011d1008f79f41c49dc1eb9b to your computer and use it in GitHub Desktop.
Save wutlu/6267b7b5011d1008f79f41c49dc1eb9b to your computer and use it in GitHub Desktop.
function data(array $allowed = [])
{
$source = file_get_contents('http://www.koeri.boun.edu.tr/scripts/lst0.asp');
$source = iconv('ISO-8859-9', 'UTF-8', $source);
preg_match('/<pre>(.*?)<\/pre>/s', $source, $match);
$lines = explode(PHP_EOL, $match[0]);
$lines = array_map(function($line) use ($allowed) {
$line = preg_replace(array('/\s{2,}/', '/[\t\n]/'), '_____', $line);
$cols = explode('_____', $line);
if (count($cols) >= 9)
{
$arr = [];
$keys = [
'tarih',
'enlem',
'boylam',
'derinlik',
'md',
'ml',
'mw',
'yer',
'cozum_niteligi',
'diger'
];
foreach ($cols as $key => $col)
{
if (@$allowed[$keys[$key]])
{
$arr[$keys[$key]] = $col;
}
}
return $arr;
}
}, $lines);
$lines = array_values(array_filter($lines));
unset($lines[0]);
$lines = array_values($lines);
return $lines;
}
$data = data([
'tarih' => true,
'enlem' => true,
'boylam' => true,
'derinlik' => true,
'md' => true,
'ml' => true,
'mw' => true,
'yer' => true,
'cozum_niteligi' => true,
'diger' => true
]);
print_r($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment