Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

php simple html dom parse img html5 attributes?

How to use simple html dom parse img html5 attribute: data-original

$htmls = '<img class="lazy" alt="Nubifragio a Verbania , ferite 2 turiste  Gravi danni, chiesto stato di calamità    foto" title="Nubifragio a Verbania , ferite 2 turiste  Gravi danni, chiesto stato di calamità    foto" data-original="http://www.repubblica.it/images/2012/08/26/130634575-506cc9ae-11b8-4a53-920c-539a3811e46b.jpg" src="http://www.repubblica.it/static/images/homepage/2012/lazy.png" width="130" height="98" style="display: inline; ">';
$html = str_get_html($htmls);
$fata = $html->find('img'); 
foreach($fata as $newimage){
    echo $newimage->data-original; //0
    echo $newimage->src; //http://www.repubblica.it/static/images/homepage/2012/lazy.png
}

I could get the attribute src, but data-original return 0

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$newimage->data-original;

means

$newimage->data - original;

A way round this is to try:

$property = 'data-original';
$newimage->$property;

or, to use the alternative syntax:

$newimage['data-original'];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...