【发布时间】:2011-12-13 01:02:22
【问题描述】:
我将以下脚本用于轻量级 DOM 编辑器。但是,我的for 循环中的nodeValue 正在将我的html 标记转换为纯文本。 nodeValue 的 PHP 替代品是什么,可以维护我的 innerHTML?
$page = $_POST['page'];
$json = $_POST['json'];
$doc = new DOMDocument();
$doc = DOMDocument::loadHTMLFile($page);
$xpath = new DOMXPath($doc);
$entries = $xpath->query('//*[@class="editable"]');
$edits = json_decode($json, true);
$num_edits = count($edits);
for($i=0; $i<$num_edits; $i++)
{
$entries->item($i)->nodeValue = $edits[$i]; // nodeValue strips html tags
}
$doc->saveHTMLFile($page);
【问题讨论】:
标签: php dom domdocument