Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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 SimpleHTMLDom:调用数组上的成员函数find()_Php_Simple Html Dom - Fatal编程技术网

Php SimpleHTMLDom:调用数组上的成员函数find()

Php SimpleHTMLDom:调用数组上的成员函数find(),php,simple-html-dom,Php,Simple Html Dom,所以我想在一个大的html页面中循环特定的TD。我使用simplehtmldom就是为了实现这一点。问题是如果我不把每一步都放在前面,我就不能让它工作 这是我的php include('../inc/simple_html_dom.php'); $html = file_get_html("http://www.bjork-family.com/f43-london-stories"); // I just put the dom of pagebody into TEST $test = $

所以我想在一个大的html页面中循环特定的
TD
。我使用simplehtmldom就是为了实现这一点。问题是如果我不把每一步都放在前面,我就不能让它工作

这是我的php

include('../inc/simple_html_dom.php');
$html = file_get_html("http://www.bjork-family.com/f43-london-stories");
// I just put the dom of pagebody into TEST
$test =  $html->find('#page-body');
foreach($test->find('img') as $element) 
{
    echo "<img src='" . $element->src . "'/>" . '<br>';
}
第39行是这一行吗

foreach($test->find('img') as $element) 
我尝试了很多不同的方法,如果我能做到这一点:

// Create DOM from URL or file
$html = file_get_html('http://www.bjork-family.com/f43-london-stories');
foreach($html->find('img') as $element) 
       echo $element->src . '<br>'; 
//从URL或文件创建DOM
$html=file\u get\u html('http://www.bjork-family.com/f43-london-stories');
foreach($html->find('img')作为$element)
echo$element->src'
';
那就行了

所以当我这样做的时候,它似乎起了作用

foreach($html->find('div') as $element) 
    {
        if($element->id == 'page-body')
        {
            echo $element->id;
            echo "EXIST <br>";
        }
        // echo "<img src='" . $element->src . "'/>" . '<br>';
    }
foreach($html->find('div')作为$element)
{
如果($element->id==“页面正文”)
{
echo$element->id;
回声“存在
”; } //回显“src.”“/>“
”; }
但我不想只使用foreach搜索我的html,有没有其他方法可以到达我的位置,然后循环(我必须在表中通过tr循环)

现在,
$test
是一个数组

$test =  $html->find('#page-body', 0);
现在,
$test
是一个元素

foreach($test->find('img') as $element) 
{
    echo "<img src='" . $element->src . "'/>" . '<br>';
}
foreach($test->find('img')作为$element)
{
回显“src.”“/>“
”; }
现在可以了。此外,您还可以通过以下方式简化:

foreach($test->find('#page-body img') as $element) 
{
    echo "<img src='" . $element->src . "'/>" . '<br>';
}
foreach($test->find(“#页面主体img”)作为$element)
{
回显“src.”“/>“
”; }
foreach($test->find('img') as $element) 
{
    echo "<img src='" . $element->src . "'/>" . '<br>';
}
foreach($test->find('#page-body img') as $element) 
{
    echo "<img src='" . $element->src . "'/>" . '<br>';
}