I have post content in sql database where special char are already escaped with htmlspecialchars($content, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
.
I use the php template engine Twig to render my template (with no framework, only php vanilla). Here is my problem : Twig escape a second time the ampersand "&" char, which result in display ugly string in the webpage, like :
Here is a <script>window.alert("hello");</script> test
When i use the filter raw
in Twig, that solve the problem. But after some research, people say that it is not safe at all, but I can't find a real solution.
So my question is : can I use raw
filter in my case, because $content
is already escaped by PHP ? Or there is a better and safer way to do this ?
I try to use raw
filter and that work, also {% autoescape false %}
work, but I want to be really sure that it is safe to render.