1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <?php
require 'flight/Flight.php';
Flight::route('/', function(){
$ch = curl_init();
$timeout = 0; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://m.jeuxvideo.com/forums/42-51-60392683-1-0-1-0-la-flemme-est-genetique.htm#post_983955211');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($file_contents);
$xpath = new DOMXPath($dom);
$domExemple = $xpath->query("//div[@class='post']");
$date = $xpath->query("//div[@class='date-post']");
$result = [];
$i = 0;
foreach ($domExemple as $exemple) {
foreach($date as $datepost){
$result[$i++] = ltrim($exemple->nodeValue);
$result[$i++][$i] = $datepost->nodeValue;
}
}
?><pre><?php
print_r($result);?></pre><?php
});
Flight::start(); |
Partager