Hello Kerry, i am happy to help. I am always thankful whenever someone helps me. Giving back to the community is a good thing.
you mentioned that you don’t know why you had to use decode three times and i haven’t explained it clearly. i am usually so tired that i struggle to form sentences. I often sleep five hours per day. My life is hectic right now. Anyway, i believe that php will ignore some of your entries because you are entering partially encoding strings. Thus, quotes will slip through the decode so you have to decode again and again depending upon the text entered. You also added ENT_NOQUOTES which complicated the matter.
if you have xampp, then you can play with code and have no consequences to pay. Try it yourself.
Enter <script>alert("test");</script>
into a form. submit the form.
Use echo htmlentities($_POST['message'], ENT_QUOTES, 'utf-8');
this will display <script>alert("test");</script>
if you only use html_entity_decode, then the script will execute and the alert box will appear. this is very bad.
now, i am not n expert so i don’t know if i am correct but i can’t see how my xampp and pc is any different than yours. i don’t like the idea of displaying gibberish as, say, a username:
<script>alert("test");</script>
so i prefer to prevent the code from being executed but not displaying html entities in place of rendered entities. I only ever read about using htmlentities to escape output, but this produces the opposite effect of what i want. I want it to be escaped but also rendered as code on the screen. I’ve played with this long enough now and when i use htmlentities with html_entity_decode, then i get the rendered code that i am looking for. But this is dangerous if you do not properly clean. Thus, i use html_entity_decode twice, then htmlentities(html_entity_decode()) to get the desired results:
Hello, <script>alert("test");</script>
instead of Hello, <script>alert("test");</script>
.
i have yet to find reference material about this but it seems to work. However, i am not an expert, so i don’t know if it is correct or not. maybe it is not supposed to work but php has a bug. If the bug were to be repaired, then the code would execute. In this case, i recommend that you just stick with rendering htmlentities() output.