I want to code a php function which connects to a wikipedia url and get the content of the wikipedia article. I use cURL with php. I refer to this blog .
The problem is: the function does not see the url's content and returns error.
This is my code:
<?php
$wikipediaURL = 'http://fr.wikipedia.org/wiki/Megadeth';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $wikipediaURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Le blog de Samy Dindane (www.dinduks.com)');
$resultat = curl_exec ($ch);
curl_close($ch);
$wikipediaPage = new DOMDocument();
$wikipediaPage->loadHTML($resultat);
foreach($wikipediaPage->getElementsByTagName('div') as $div){
if($div->getAttribute('id') == "bodyContent"){
$description = '<p>' . $div->getElementsByTagName('p')->item(0)->nodeValue. '</p>';
$description = preg_replace('/\[[0-9]*\][,]|\[[0-9]*\]/', '', $description);
echo $description; }}
?>
This is the error message:
Warning: DOMDocument::loadHTML(): Empty string supplied as input in C:\wamp\www\Project1\wiki5.php on line 12
I use other code samples with the same function, and it does not work only with wikipedia url.
Any help please! Thanks