duansaoguan7955 2013-10-01 23:09
浏览 56
已采纳

DomDocument innerHTML在简单的PHP脚本中不起作用

innerHTML in php DomDocument does not work in simple PHP script and I can't set the inner html of html element by id, There is no error/warning! what should I do ?

(I also checked the file name and the html element id)

    $index = new DomDocument;
    $index->validateOnParse = true;
    $index->formatOutput = true;


    $index->loadHTML('index.php');

    $index->getElementById('element-unique-id')->innerHTML = 'some text';


    echo $index->saveHTML();

the out put is blank.

  • 写回答

1条回答 默认 最新

  • douben1891 2013-10-01 23:27
    关注

    As there's no inneHTML-property, you can solve it by creating and appending a new DOMText node:

    $index->getElementById('element-unique-id')
          ->appendChild(new DOMText('some text'));
    

    See also The DOMText class and DOMText::__construct.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部