如何获取img标签的src属性? [英] How do I get the src attribute of img tags?

查看:873
本文介绍了如何获取img标签的src属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用外部网址加载DOM:

I load the DOM by an external url as such:

$dom = new DOMDocument;
$dom->loadHTMLFile( "external_url.html" );

$arrayOfSources = array();

foreach( $dom->getElementsByTagName( "img" ) as $image )
    $arrayOfSources[] = $image->item(0)->getAttribute("src");

这样我想将img标签的所有src属性存储在数组中,但我保留得到错误致命错误:调用未定义的方法DOMDocument :: item()

This way I want to store all the src attributes of the img tags in an array, but I keep getting the error Fatal error: Call to undefined method DOMDocument::item()

我在这里缺少什么?如何从html中的img标签中提取所有src属性?

What am I missing here? How do I extract all the src attributes from the img tags in an html?

推荐答案

删除 < item(0) part。

这篇关于如何获取img标签的src属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆