JSON'dan şöyle bir veri geliyor...
"place":"269km NNW of Farallon de PajarosBen bu ifadenin "of" kelimesinden önceki kısmını göstermek istemiyorum. Onu aşağıda kodların tamamını paylaştığım dosyanın $deprem->yer kısmında çözdüm. Ama JSON bazen veriyi bu "of" kelimesi olmadan gönderiyor. Şu şekilde yani;
"place":"Central East PacificO zaman da aynen yazdırmak istiyorum. Nasıl yapabilirim?
Kısacası;
"place":"269km NNW of Farallon de Pajarosgeldiğinde Farallon de Pajaros olanı çekmek
"place":"Central East Pacificolarak geldiğinde ise Central East Pacific olarak çekmek istiyorum.
Güncel kod bu şekilde;
<?php
echo "<pre>
.................DÜNYADAKİ SON DEPREMLER....................
Büyüklük
Tarih Saat Enlem(N) Boylam(E) Derinlik(km) MD ML Mw Yer Çözüm Niteliği
---------- -------- -------- ------- ---------- ------------ -------------- --------------
";
class Deprem {
public $siddet;
public $tarih;
public $saat;
public $enlem;
public $boylam;
public $derinlik;
public $yer;
}
function eng2tr($str)
{
$from_arr=array("ç", "Ç", "ğ", "Ğ", "ı", "İ", "ö", "Ö", "ü", "Ü", "ş", "Ş");
$to_arr=array("c", "C", "ğ", "Ğ", "i", "I", "o", "O", "u", "U", "s", "S");
return strtoupper(str_replace($from_arr, $to_arr, $str));
}
$site = file_get_contents("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_month.geojson");
$depremler = array();
$data = json_decode ($site,JSON_UNESCAPED_UNICODE);
$i = 0;
foreach ($data ["features"] as $value) {
$deprem = new Deprem();
$deprem->siddet = $value["properties"]["mag"];
$bilgiler = explode(" ", date('d.m.Y H:i:s', (($value["properties"]["time"])/1000)));
$deprem->tarih = $bilgiler[0];
$deprem->saat = $bilgiler[1];
$deprem->boylam = $value["geometry"]["coordinates"][0];
$deprem->enlem = $value["geometry"]["coordinates"][1];
$deprem->derinlik = $value["geometry"]["coordinates"][2];
$deprem->yer = strtoupper(explode("of",$value["properties"]["place"])[1]);
$depremler[$i++] = $deprem;
}
// arsort($depremler);
foreach ($depremler as &$deprem){
echo "".$deprem->tarih." "; // tarih
echo "".$deprem->saat." "; // saat
echo "".$deprem->enlem." "; // enlem
echo "".$deprem->boylam." "; // boylam
echo "".$deprem->derinlik." "; // derinlik
echo "-.- "; // MD
echo "".$deprem->siddet." "; // deprem şiddeti
echo "-.- "; // MW
echo ""; // BOŞLUK
echo "".$deprem->yer." "; // yer
echo " İlksel
"; // BOŞLUK
}
echo "
</pre>";
?>