This article describes an example of how PHP simply handles special characters entered in a form. Share it with everyone for your reference, the details are as follows:
<html> <body> <?php if ($_POST['submitted'] == "yes"){ $yourname = $_POST['yourname']; $yourname = trim ($yourname); $yourname = strip_tags ($yourname); $yourname = htmlspecialchars ($yourname); $yourname = addslashes ($yourname); echo $yourname . "<br />"; ?><a href="index.php">Try Again</a><?php } if ($_POST['submitted'] != "yes"){ ?> <form action="index.php" method="post"> <p>Example:</p> <input type="hidden" name="submitted" value="yes" /> Your Name: <input type="text" name="yourname" maxlength="150" /><br /> <input type="submit" value="Submit" style="margin-top: 10px;" /> </form> <?php } ?> </div> </body> </html>
Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of Usage of PHP Strings", "Summary of Usage of PHP Operations and Operators", "Introduction to PHP Basic Syntax Tutorial" and "php Summary of methods to prevent SQL injection》
I hope this article will be helpful to everyone in PHP programming.