Home > Article > Backend Development > PHP simple method to handle special characters entered in form_php tips
The example in this article describes 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 on this site: "Summary of PHP string (string) usage", "Summary of PHP operations and operator usage ", "Introduction to PHP Basic Syntax Tutorial" and "Summary of PHP SQL Injection Prevention Methods"
I hope this article will be helpful to everyone in PHP programming.