2

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?

asked Jun 15, 2016 at 9:54

1 Answer 1

1

You have to escape the slash:

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

answered Jun 15, 2016 at 10:09

6 Comments

Backslash remains in the results.
@revo what do you aim to achieve with this exactly?
I'm not going to achieve something but you should have noted what I already commented. Also you can't do such escaping within a large HTML input so it's totally a temporary solution.
@revo I thought your comment was from the author of the question so I was wondering why is he doing this. Sorry for the misunderstanding.
No problem @TheFallen
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.