Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对非对象上的成员函数item()的xmlDom调用_Php_Html_Xmldom - Fatal编程技术网

Php 对非对象上的成员函数item()的xmlDom调用

Php 对非对象上的成员函数item()的xmlDom调用,php,html,xmldom,Php,Html,Xmldom,嗨,我有一个有行和列的表 <table> <tr> <td style="font-size:14px"></td> </tr> <tr> <td background="image.jpg"></td> </tr> </table> 然后循环它,通过此代码获得每个td标记 for($i = 0; $i<$td->length; $

嗨,我有一个有行和列的表

<table>
  <tr>
    <td style="font-size:14px"></td>
  </tr>
  <tr>
    <td background="image.jpg"></td>
  </tr>
</table>
然后循环它,通过此代码获得每个
td
标记

for($i = 0; $i<$td->length; $x++){
   print_r($td->item($i));
}
而这个没有

<table>
  <tr>
    <td style="font-size:14px;"></td>
  </tr>
  <tr>
    <td background="image.jpg"></td>
  </tr>
</table>


我的目标是访问
td
标记内的
background
属性

使用
foreach
让生活更轻松

foreach ($dom->getElementsByTagName('td') as $tag) {
    if ($tag->getAttribute('background')) {
        echo $tag->getAttribute('background'); //"prints" image.jpg
    }
}

谢谢您完成了修订,这使我的功能更简单,现在可以正常工作了。谢谢!很高兴能帮上忙,伙计
<table>
  <tr>
    <td style="font-size:14px;"></td>
  </tr>
  <tr>
    <td background="image.jpg"></td>
  </tr>
</table>
foreach ($dom->getElementsByTagName('td') as $tag) {
    if ($tag->getAttribute('background')) {
        echo $tag->getAttribute('background'); //"prints" image.jpg
    }
}