让我感到困惑的是:
<?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>
为什么会这样做,我该如何避免呢?
答案 0 :(得分:1)
你必须逃避斜线:
$newdoc->loadHTML("<script>document.write('<\/scr' + 'ipt>');</script>");