Alex Channelunity
Alex Channelunity

Reputation: 21

php DomDocument->saveHTML removes slash

Just the part that confuses me:

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

It will output:

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

Why does it do that and how can I avoid it?

Upvotes: 2

Views: 244

Answers (1)

thefallen
thefallen

Reputation: 9749

You have to escape the slash:

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

Upvotes: 1

Related Questions