Merhabalar tüm veriyi çekmekte bu yüzden kısıtlamak için nasıl yaparım
<?php
// API URL'si
$api_url = 'https://jsonplaceholder.typicode.com/posts'; // JSON array döndüren API URL'si
// file_get_contents ile JSON verisini al
$response = file_get_contents($api_url);
// JSON yanıtını PHP dizisine çevir
$data = json_decode($response, true);
// Hata kontrolü yap
if ($data) {
// JSON array verisini döngü ile işleyelim
echo "<h1>Post Listesi:</h1>";
foreach ($data as $post) {
// JSON array'den gelen her bir post objesinin başlık ve içeriğini yazdır
echo "<h2>" . $post['title'] . "</h2>";
echo "<p>" . $post['body'] . "</p>";
}
} else {
// API'den alınan yanıt geçersizse hata mesajı yazdır
echo "Hata: Veriler alınamadı.<br>";
}
?>