所以昨天我问了关于将数据发布到表格中的问题。现在它确实给出了一个很好的结果,但至少需要 30 秒才能得到结果。我用 curl 试过了,我几乎立刻就得到了结果。现在我的问题是:我如何将 curl 中的数据发布到表格中。
我的代码:
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
print curl_download('http://services.runescape.com/m=itemdb_rs/api/catalogue/items.json?category=1&alpha=a&page=1');
结果:
{"total":5,"items":[{"icon":" http://services.runescape.com/m=itemdb_rs/4173_obj_sprite.gif?id=4798 ","icon_large":" http:// services.runescape.com/m=itemdb_rs/4173_obj_big.gif?id=4798 ","id":4798,"type":"Ammo","typeIcon":" http://www.runescape.com/img/类别/弹药","name":"Adamant Brut","description":"Blunt adamantite arrow...ouch","current":{"trend":"neutral","price":222},"today ":{"趋势":"中性","价格":0}},{"图标":" http://services.runescape.com/m=itemdb_rs/4173_obj_sprite.gif?id=810 ","icon_large":" http://services.runescape.com/m=itemdb_rs/4173_obj_big.gif?id=810 ","id":810,"type":"Ammo","typeIcon":" http:// www.runescape.com/img/categories/Ammo","name":"Adamant dart","description":"一种带有坚固尖端的致命飞镖。","current":{"trend":"neutral","price":11},"today" :{"趋势":"中性","价格":0}},{"图标":" http://services.runescape.com/m=itemdb_rs/4173_obj_sprite.gif?id=829 ","icon_large" :" http://services.runescape.com/m=itemdb_rs/4173_obj_big.gif?id=829 ","id":829,"type":"Ammo","typeIcon":" http://www. runescape.com/img/categories/Ammo ","name":"Adamant javelin","description":"An adamant tipped javelin.","current":{"trend":"neutral","price":64},"today":{"trend":"positive","price":"+1"}},{"icon":" http://services.runescape.com/m=itemdb_rs /4173_obj_sprite.gif?id=867 ","icon_large":" http://services.runescape.com/m=itemdb_rs/4173_obj_big.gif?id=867","id":867,"type":"Ammo","typeIcon":" http://www.runescape.com/img/categories/Ammo ","name":"Adamant knife","description" :"一把平衡的飞刀。","current":{"trend":"neutral","price":23},"today":{"trend":"neutral","price":0}} ,{"icon":" http://services.runescape.com/m=itemdb_rs/4173_obj_sprite.gif?id=804 ","icon_large":" http://services.runescape.com/m=itemdb_rs/4173_obj_big .gif?id=804 ","id":804,"type":"Ammo","typeIcon":" http://www.runescape.com/img/categories/Ammo ","name":"Adamant 投掷斧头","description":"平衡良好的投掷斧头。","current":{"trend":"neutral","price":180},"today":{"trend":"neutral" "价格":0}}]}
我试过谷歌,但因为我对 curl 和数组的了解为零,我没有进一步了解。