Veriyi json şeklinde alır derlemek için forearch döngüsüne alabilirsiniz.
Bu şekilde:
$site="http://localhost/api/deneme/api.php?auth=imhatimi.org&ulke=$ulke&postakodu=$postakodu";
$31=file_get_contents($site);
$31Json=json_decode($31,true);
foreach ($31Json as $key => $value){
$31veriyicekiyor=$value["derlemek istediğiniz veri"];
echo $31cek ."<br/>";
}
Kullanımı:
http://localhost/api/deneme/api.php?auth=imhatimi.org&ulke=buraya ülkenin kısaltması tr gibi&postakodu=buraya da posta kodu gireceksiniz
Bu şekilde:
$site="http://localhost/api/deneme/api.php?auth=imhatimi.org&ulke=$ulke&postakodu=$postakodu";
$31=file_get_contents($site);
$31Json=json_decode($31,true);
foreach ($31Json as $key => $value){
$31veriyicekiyor=$value["derlemek istediğiniz veri"];
echo $31cek ."<br/>";
}
Kullanımı:
http://localhost/api/deneme/api.php?auth=imhatimi.org&ulke=buraya ülkenin kısaltması tr gibi&postakodu=buraya da posta kodu gireceksiniz
PHP:
<?php
header("type: application/json; charset=utf8_general_ci");
$auth = "imhatimi.org";
if($_GET['auth'] != $auth) {
echo json_encode(array('success' => false, 'auth' => 'Yaman Karaman', 'message' => 'auth key yanlis'));
die(); }
if (isset($_GET["ulke"])) {
$ulke = addslashes(htmlspecialchars($_GET["ulke"])); }
if (isset($_GET["postakodu"])) {
$postakodu = addslashes(htmlspecialchars($_GET["postakodu"])); }
$cURL = curl_init();
curl_setopt_array($cURL,
[
CURLOPT_URL => "https://api.zippopotam.us/$ulke/$postakodu",
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_RETURNTRANSFER => 1
]);
$x = curl_exec($cURL);
curl_close($cURL);
print_r($x);
$data = json_decode($x, FALSE);
echo "<pre>";
print_r($data[1]);
$data = json_decode($x, FALSE);
echo "<pre>";
print_r($data[1]->name);
?>