1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
function parse()
{
$absent = Array(
'test' => 'inconnu',
);
//utilisation de curl et initialisation
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://site.com');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_NOBODY, FALSE);
$recup = curl_exec($curl);
curl_close($curl);
// on récupère le contenu souhaite et mon souci
preg_match('#<div id="a">Energie</div><div id="b">(.*?)</div>#is', $recup, $test);// il ne trouve rien
$sortie['test'] = (empty($test)) ? $absent['test'] : trim(utf8_decode(strip_tags($test[0])));
return $sortie;
}
//mon souci est lorsque le css est identique dans la page, comment puis-je aller trouver la bonne occurence avec preg_match
var_dump(parse()); |
Partager