我是 php 新手,在从以下 php 代码生成的数组中提取一些字段时遇到了一个典型问题:
$html=file_get_html("http://www.flipkart.com/books/9781846467622");
$e = $html->getElementById("mprodimg-id");
echo $e;
$f = $e->find('img');
echo $f['data-src'];
在代码中应用 var_dump($f) 后看到的输出数组 f 如下:-
数组 ( [0] => simple_html_dom_node 对象 ( [nodetype] => 1 [tag] => img [attr] => 数组 ( [onerror] => img_onerror(this); [data-error-url] => http: //img1a.flixcart.com/img/book.jpg [高度] => 275 [宽度] => 275 [数据-src] => http://img7a.flixcart.com/img/622/9781846467622.jpg [src] => data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////Ly8v///yH5BAEAAAMALAAAAAAAAABAAEAAAICVAEAOw== [onload] => lzld(this) [alt] => Buy Numbers [title] => Numbers ) [children ] => 数组 ( ) [节点] => 数组 ( )
我需要回显字段“data-src”的值。有人可以帮忙吗。
萤火虫看到的html如下,我需要从哪里刮掉它。
<div id="mprodimg-id" class="mprodimg">
<img width="275" height="275" title="Numbers" alt="Buy Numbers" onload="lzld(this)" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////Ly8v///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-src="http://img7a.flixcart.com/img/622/9781846467622.jpg" data-error-url="http://img1a.flixcart.com/img/book.jpg" onerror="img_onerror(this);">
</div>