【发布时间】:2013-08-05 11:37:36
【问题描述】:
所以昨天我询问了将数据发布到表格中的问题。现在它确实给出了一个很好的结果,但至少需要 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/categories/Ammo","name":"Adamant Brut","description":"钝的精金箭……哎哟","current":{"trend":"neutral","price": 222},"今天":{"趋势":"中性","价格":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":{"趋势":"neutral","price":11},"today":{"trend":"neutral","price":0}},{"icon":"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":"一个坚固的尖头标枪。" ,"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刀"," description":"一把平衡的飞刀。","current":{"trend":"neutral","price":23},"today":{ "趋势":"中性","价格":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":"弹药" ,"typeIcon":"http://www.runescape.com/img/categories/Ammo","name":"Adamant 飞斧","description":"平衡良好的飞斧。","current":{"trend":"neutral","price" :180},"today":{"trend":"neutral","price":0}}]}
我尝试过 google,但因为我对 curl 和数组的了解为零,所以我没有进一步了解。
【问题讨论】:
-
通过 Post it in table,你是否只想渲染一个取回数据的表格?
-
@MajorCaiger 我不完全明白你的意思,但这是昨天回答我的问题后的结果:puu.sh/3UfYe.png