Ik ben bezig om een systeem te maken met onderwerpen. En bij elk onderwerp het eerste alinea van Wikipedia te gebruiken. En de eerste <p> is ook meteen de eerste alinea van de tekst.
Weet iemand hoe dat moet?
Alvast bedankt voor de reacties.
Ik heb ook gezocht maar zag direct een zeer uitgebreide API en heel veel informatie, inclusief een tutorial en instructie video. http://www.mediawiki.org/wiki/API:Main_page
<?php
class toIBAN
{
private $obj;
private $error;
function __construct()
{
$this->error = false;
}
public function getError()
{
return $this->error;
}
public function getObject()
{
return $this->obj;
}
public function getTitle()
{
return $this->obj->query->pages->{296302}->revisions[0]->{'*'};
}
public function run($vraag)
{
$serverurl = 'http://en.wikipedia.org/w/api.php?format=json&action=query&titles='. $vraag .'&prop=revisions&rvprop=content';
if(!$json = @file_get_contents($serverurl))
{
$this->error = 'No data received, please make sure connection is working and requested API exists';
return;
}
$this->obj = json_decode($json);
if(isset($this->obj->error))
{
$this->error = $this->obj->error;
return false;
}
return true;
}
};
$iban = new toIBAN();
if($iban->run('Nederland'))
{
//print_r($iban->getObject());
echo '<br><br>';
echo 'Title: '.$iban->getTitle().'<br>';
}
else
{
echo $iban->getError();
}
?>
Dan komt dit op de site te staan:
Title: {{Wiktionary}} '''Nederland''' is the Dutch name for the '''[[Netherlands]]'''. It is also the name of several villages: * [[Nederland, Overijssel]], in Steenwijkerland, Netherlands * [[Nederland, Colorado]], United States * [[Nederland, Texas]], United States ==See also== * [[Netherlands (disambiguation)]] {{geodis}} [[it:Nederland]]
Hoe kan ik dit voor de mensen een mooie tekst van maken. En hoe moet ik de paginaID weten van elk pagina van wikipedia?
[size=xsmall]Toevoeging op 09/09/2013 19:53:24:[/size]
Ik heb het bedankt voor alle reacties.
<?php
$url = 'http://nl.wikipedia.org/w/api.php?action=parse&page=Nederland&format=json&prop=text§ion=0';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "TestScript"); // required by wikipedia.org server; use YOUR user agent with YOUR contact information. (otherwise your IP might get blocked)
$c = curl_exec($ch);
$json = json_decode($c);
$content = $json->{'parse'}->{'text'}->{'*'}; // get the main text content of the query (it's parsed HTML)
// pattern for first match of a paragraph
$pattern = '#<p>(.*)</p>#Us'; // http://www.phpbuilder.com/board/showthread.php?t=10352690
if(preg_match($pattern, $content, $matches))
{
// print $matches[0]; // content of the first paragraph (including wrapping <p> tag)
print strip_tags($matches[1]); // Content of the first paragraph without the HTML tags.
}
?>