0

我想使用简单的 html dom 解析器从元素中获取 innerHtml。

例如:

$s = "      <div class="a">
                <p>I don't want this stuff</p>
                <div class="b">
                    <input type="button" value="testing">
                    <p>I want this stuff</p>
                </div>
            </div> ";

$html = str_get_content($s);
$ret = $html->find('div[class=b']);

现在......我想初始化另一个对象,但使用来自 $ret 的 html。

我尝试过使用 $newSource = $ret[0]->save(),但它不起作用。在他们的文档中,它没有出现关于innerHtml 或outerHtml 的内容,只是innerText。

4

3 回答 3

1
$ret[0]->innertext

会给你元素的内部 HTML(即使它被称为文本,它实际上是整个 html)

于 2014-07-03T13:05:27.163 回答
0

According to the documentation there is a way to dump your dom, maybe that can be used as wenn to dump just a part of your some.

echo $ret[0]; // this should return your dom fragment

if you want another object and $object = $ret[0] isn't what you're looking for, this could help:

$html = (string) $ret[0]; // convert to html
$newSource = str_get_content($html); // create new object
于 2014-07-03T13:08:36.703 回答
0

自从我使用该课程以来已经有一段时间了,但是您尝试过吗 echo $ret->plaintext;

于 2014-07-03T13:05:06.543 回答