I'm trying to get some data from a wikipedia API but i am receiving this message.
Here is the PHP script with the small html form above:
<form action="" method="get">
<input type="text" name="busca">
<input type="submit" value="Busca">
</form>
<?php
if($_GET['busca']){
$api_url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=".ucwords($_GET['busca']).".redirects=true";
$api_url = str_replace(' ', '%20', $api_url);
if($data = json_decode(file_get_contents($api_url))){
foreach($data->query->pages as $key=>$val){
$pageId = $key;
break;
}
$content = $data->query->pages->$pageId->extract;
header('Content-Type:text/html; charset=utf-8');
echo $content;
}
else{
echo 'Nenhum resultado encontrado.';
}
}
?>
So i get:
Notice: Undefined property: stdClass::$extract in C:\xampp\htdocs\wiki\index.php on line 18