I’m trying to validate a comment form using AJAX/PHP, very nearly done now except the strip_tags function in php doesn’t seem to remove all elements. Here’s what I have:
$msg = $_POST['message'];
$msg = strip_tags( $msg );
This function only seems to be removing the closing tags. E.g. <div> entered into the message box is not being removed where </div> is being removed.
I want to literally remove every html element in the message. How do I achieve this?
Thanks, Dan.
Edit:
I feel like a complete idiot!
I have a validate function separate from my show comment function and just realised my mistake. I was never running strip_tags on the message I was displaying!
Anyway, thanks for trying to help!
one thing that
strip_tags()can fail with ishtmlentities().it will make
<div>appear as%3Cdiv%3Efor example.Try this. htmlentities will convert code eg.
%3Cto HTML, eg.<you should be able to see what you’re trying to debug by comparing these: