Simplehtmldom innertext无效

时间:2013-07-25 01:47:13

标签: php html xml dom simple-html-dom

所以我使用的是simple_html_dom:

http://simplehtmldom.sourceforge.net/

我有这段代码:

$j = '
  <itemBody>
        <div>films - to watch (Simple Present)<br/>
            <textEntryInteraction responseIdentifier="RESPONSE_1"/>
        </div>
    </itemBody>';
  $dom = new simple_html_dom;
  $dom->load($j, TRUE);
  echo $dom->innertext;

然后返回:

 <itembody>
        <div>films - to watch (Simple Present)<br/>
            <textentryinteraction responseidentifier="RESPONSE_1"/>
        </div>
    </itembody>

为什么不删除itembody标签? (它只是变成了小写。)

1 个答案:

答案 0 :(得分:0)

我不相信innertext级别存在dom属性。试试echo $dom->plaintext;

对于元素级别的innertext,从dom对象中提取element并获取innertext

$elm = $dom->find("div",0);
echo $elm->innertext;