簡體   English   中英

簡化php curl代碼

[英]Simplify php curl code

我試圖從網址獲取JSON。 我的代碼正在運行,但我認為我可以做得更好。 (刪除json_decode或json_encode)。 現在這就是我所擁有的:(編輯:我仍然想使用卷曲)

<?php
 $curl = curl_init('url');

 curl_setopt($curl, CURLOPT_URL, 'url');
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

 $result = curl_exec($curl);

 curl_close($curl);

 $data = json_decode($result, true);

 echo json_encode($data["name"]);

 ?>

你可以試試這個:

$data = json_decode(file_get_contents('php://input'));
print_r($data);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM