2016-09-05 1 views

Répondre

1

C'est intéressant car il semble que pic_id est cassé json. Nous pouvons encore obtenir les données avec un regex:

$str = <<<EOF 
<div class="pic" style="top:0px;left:0px;height:149px;" data='{"pic_id":"06e50224ab189";}' pic-descr=" this title " data-index="0"> 
</div> 
EOF; 

$html = str_get_html($str); 
$div = $html->find('.pic', 0); 

if(preg_match('/:"(.*?)"/', $div->data, $m)){ 
    echo "pic_id is: " . $m[1] . "\n"; 
} 
echo "pic-descr is: " . $div->{'pic-descr'} . "\n"; 

Si le JSON n'a pas été cassée, vous pouvez faire: json_decode($div->data)->pic_id

+0

Je comprends OP marqué ce 'simple-html-dom', mais juste pour confirmer,' str_get_html' n'est pas native natif PHP intégré? en fait-il partie http://simplehtmldom.sourceforge.net/? –

+0

@the_velour_fog - c'est correct. – pguardiario