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
You have to escape the slash:
$newdoc->loadHTML("<script>document.write('<\/scr' + 'ipt>');</script>");
answered Jun 15, 2016 at 10:09
6 Comments
revo
Backslash remains in the results.
thefallen
@revo what do you aim to achieve with this exactly?
revo
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.
thefallen
@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.
revo
No problem @TheFallen
|
lang-php