I'm using TinyMCE 4 on a project, where I need to be able to pre-populate the textarea with HTML that was submitted through POST (for server-side error handling without deleting all their work) I know that a textarea works mostly like a tag, in that HTML inside is not parsed into DOM, so most sites show the demo:
<textarea name="demo"><?=$_POST['demo']?></textarea>
but what happens when a user submits HTML that includes an unmatched <textarea>
or </textarea>
tag?
Is there a standard way to manage this risk?
use htmlspecialchars($_POST['demo'])
in php when outputing
Remove only the <textarea>
tags from the user input. Please see this post using regular expressions. It tells you how to remove only certain tags (unlike htmlentities
) which removes all tags.
htmlentities function will replace every html caracter (such as <) to one that will display correctly but wont break your html. http://www.php.net/manual/en/function.htmlentities.php
Use xmp tag instead of textarea. It will display html as itself.