我想从维基百科使用php获取关于我的查询的一些信息。我想要有一个描述,标题,IMG网址(如果存在)和一些关于它的附带信息。例如像谷歌维基百科的信息,有很多边信息。维基百科搜索带有多边信息的api
直到现在我只有描述&标题。
我的代码:
$q = str_replace("#", "", ucwords($query));
$opts = array('http' =>
array(
'user_agent' => 'Mozilla Firefox www (http://www.mozilla.org)'
)
);
$context = stream_context_create($opts);
$url = 'en.wikipedia.org/w/api.php?action=opensearch&search='.$q.'&limit=1&namespace=0&format=xml';
@$wiki_arr = simplexml_load_file($url);
if(@$wiki_arr->Section->Item->Text == "" or @strtolower($wiki_arr->Section->Item->Text) != strtolower($q))
{
return "";
}
$title = $wiki_arr->Section->Item->Text;
$description = $wiki_arr->Section->Item->Description;
$url = $wiki_arr->Section->Item->Url;
$result = "".$title.", ".$description.", ".$url."";
那么究竟是什么问题? – Billy 2014-10-19 13:36:19
我怎样才能使用维基百科api的信息? – R2D2 2014-10-19 14:01:37
你已经知道你已经从它获得信息(描述,标题)。维基百科API在这里有一个帮助页面[WIKI API](http://www.mediawiki.org/wiki/API:Main_page) – Billy 2014-10-19 14:05:58