I want to take some information about my query from wikipedia using php. I want to have a description, title, img url (if exists), and some side information about it. For example like the google wikipedia information, with much side information.
Until now i have only the description & title.
My code:
$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."";