Skip to content

Instantly share code, notes, and snippets.

@akinozgen
Last active January 22, 2020 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akinozgen/1e9ae75b6b51a221fd23d1ceb3db8089 to your computer and use it in GitHub Desktop.
Save akinozgen/1e9ae75b6b51a221fd23d1ceb3db8089 to your computer and use it in GitHub Desktop.
Kandilli Son Depremler PHP API(cik) https://kandilli-son-depremler-api.herokuapp.com/
<?php
header('Content-type: text/json');
$content = iconv('windows-1254', 'utf-8', file_get_contents("http://www.koeri.boun.edu.tr/scripts/lst0.asp"));
preg_match_all("/<pre>(.*?)<\/pre>/s", $content, $pre);
$rows = explode("\n", str_replace(["<pre>", "</pre>"], "", $pre[0][0]));
for ($i = 0; $i < 7; $i++) array_shift($rows);
$rows = array_filter(array_map(function ($row) {
$parts = explode(' ', $row);
$parts = array_filter($parts, function ($row) {
return strlen($row) > 1;
});
$parts = array_map(function ($part) {
if ($part === '-.-') return null;
return strip_tags(
htmlspecialchars(
str_replace(
["\t", "\s", "\w", "\r", "\n"],
'',
trim($part)
)
)
);
}, $parts);
return array_values($parts);
}, $rows), function ($row) {
return count($row) > 2;
});
$tableData = [];
foreach ($rows as $row) {
$tableData[] = [
"timestamp" => $row[0],
"geolocation" => sprintf("%s,%s", $row[1], $row[2]),
"depth" => $row[3],
"md" => $row[4],
"ml" => $row[5],
"mw" => $row[6],
"address" => $row[7],
"precision" => $row[8],
"rev_date" => isset($row[9]) ? $row[9] : null
];
}
echo json_encode($tableData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment