php ile json data veren ekranı çekip yazdırmak istiyorum
4
●128
- 19-12-2024, 00:26:41İki satır kod için para istemek de ne bileyim!
Al kardeş sana örnek kod.
<?php // Hedef URL $url = "https://x.com/veri.json"; // cURL ile veriyi çek $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // SSL doğrulamasını devre dışı bırak (güvenli olmayan bağlantılar için) $response = curl_exec($ch); // Hata kontrolü if (curl_errno($ch)) { echo "cURL Hatası: " . curl_error($ch); curl_close($ch); exit; } curl_close($ch); // JSON verisini kontrol et if ($response) { // Çıktıyı bir text dosyasına yaz $filename = "output.txt"; $result = file_put_contents($filename, $response); if ($result !== false) { echo "Veri başarıyla '$filename' dosyasına yazıldı."; } else { echo "Dosya yazma hatası."; } } else { echo "Veri alınamadı."; } ?>