The easiest way is to simply prevent users from entering HTML tags. If you strip_tags () or htmlspecialchars () are all user input, then there is no way to enter the <script> .
If you want to allow limited markup, then you can use syntax like bbcode (finding the PHP library should not be difficult for this, although I have never done it myself, so I have no recommendations for this front), or you can use HTMLpurifier to limit markup that users can enter.
source share