Simplehtmldom内部文本不起作用


Simplehtmldom innertext not working

所以我使用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标签?(它只是变成了小写。)

我不认为innertext属性存在于dom级别中。尝试echo $dom->plaintext;

对于元素级别中的innertext,从dom对象中提取一个element,并获得内部文本

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