我正在使用 Wikipedia API 来获取我的网站的图像和描述,我需要你对图像的帮助。目前我正在使用这个:
$wurl = "http://en.wikipedia.org/w/api.php?action=query&prop=extracts|info|images&titles=".$wsearch."&format=json&explaintext&redirects&inprop=url&indexpageids&exintro";
$wjson = file_get_contents($wurl);
$wdata = json_decode($wjson);
$wpageid = $wdata->query->pageids['0'];
if ($wpageid == -1)
{
}
else
{
echo"
<div id='images'>
<p style='padding-bottom:8px;border-bottom: 6px solid #333;width:100%;'>Images for <b>$search</b>:</br></p>
<div class='resultbox random-color-".rand(1,3)."'>
";
foreach($wdata->query->pages->$wpageid->images as $iimages)
{
$ititle = $iimages->title;
$iname = $ititle;
$ifilename = str_replace(" ", "_",$iname);
$idigest = md5($ifilename);
$ifolder = $idigest[0] . '/' . $idigest[0] . $idigest[1] . '/' . urlencode($iname);
$iurl = 'http://upload.wikimedia.org/wikipedia/commons/' . $ifolder;
echo"
<img style='height:100px;' src='$irurl'>
";
}
echo"
</div>
</div>
";
}
要从 url 回显每个单独的图像:
但是,我无法取回任何东西,或者至少我的页面上没有显示任何内容。我对 JSON 很陌生,所以有人可以向我解释我做错了什么吗?我希望你能告诉我和未来的观众这样做,因为它真的很烦人......哈哈,无论如何提前谢谢。
编辑:
<div class="resultbox random-color-3">
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 4="" 4a="" commons-logo.svg'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" f="" fe="" crystal_clear_app_browser.png'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" e="" e5="" eric_schmidt_at_the_37th_g8_summit_in_deauville_037.jpg'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" b="" b6="" factory_1b.svg'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" a="" a4="" flag_of_the_united_states.svg'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 2="" 20="" google-logo.svg'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" b="" b7="" google1998.png'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 6="" 69="" google_appliance.jpg'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 5="" 54="" google_mountain_view_campus_dinosaur_skeleton_%27stan%27.jpg'=""/>
<img src'http:="" upload.wikimedia.org="" wikipedia="" commons="" 8="" 8c="" google_mountain_view_campus_garden.jpg'=""/>
</div>
它似乎正在删除所有/而不是用下划线替换空格......有什么想法吗?