Ca paraît effectivement plus simple. Le code une fois adapté à mes besoins donne ceci :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?php
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://m.jeuxvideo.com/forums/42-51-55256100-1-0-1-0-le-chemin-de-la-solitude.htm');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument;
$dom->loadHTML($file_contents);
$result = [];
foreach ($dom->getElementsByTagName('p') as $pNode) {
$content = '';
foreach ($pNode->childNodes as $childNode) {
$content .= $dom->saveHTML($childNode);
}
$result[] = $content;
}
?>
<pre><?php var_dump($result); ?></pre> |
Seulement la ligne 12 renvoie une erreur :
1 2 3 4 5 6
|
Warning: DOMDocument::loadHTML(): Tag header invalid in Entity, line: 19 in /opt/lampp/htdocs/tests/yams/alsa3.php on line 12
Warning: DOMDocument::loadHTML(): Tag section invalid in Entity, line: 25 in /opt/lampp/htdocs/tests/yams/alsa3.php on line 12
Warning: DOMDocument::loadHTML(): Tag footer invalid in Entity, line: 421 in /opt/lampp/htdocs/tests/yams/alsa3.php on line 12 |
J'ai cherché du côté de google et j'ai trouvé qu'il fallait entrer ce code :
libxml_use_internal_errors(true);
Je n'ai pas cherché donc compris pourquoi mais je te remercie pour ton aide
Je n'ai pas vraiment compris l'histoire du deuxième foreach avec le childNodes mais je vais y réfléchir
Partager