php DomDocument-> saveHTML删除斜杠

时间:2016-06-15 09:54:44

标签: php domdocument

让我感到困惑的是:

<?php
echo "Start\n";
$newdoc = new DOMDocument();
$newdoc->loadHTML("<script>document.write('</scr' + 'ipt>');</script>");    
echo $newdoc->saveHTML();
echo "\nDone\n";

将输出:

<script>document.write('' + 'ipt>');</script>

为什么会这样做,我该如何避免呢?

1 个答案:

答案 0 :(得分:1)

你必须逃避斜线:

$newdoc->loadHTML("<script>document.write('<\/scr' + 'ipt>');</script>");