Home  >  Article  >  Backend Development  >  PHP simple method to handle special characters entered in form_php tips

PHP simple method to handle special characters entered in form_php tips

WBOY
WBOYOriginal
2016-05-16 19:59:011119browse

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>
  <&#63;php
   if ($_POST['submitted'] == "yes"){
    $yourname = $_POST['yourname'];
    $yourname = trim ($yourname);
    $yourname = strip_tags ($yourname);
    $yourname = htmlspecialchars ($yourname);
    $yourname = addslashes ($yourname);
    echo $yourname . "<br />";
    &#63;><a href="index.php">Try Again</a><&#63;php
   }
   if ($_POST['submitted'] != "yes"){
    &#63;>
    <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>
    <&#63;php
   }
  &#63;>
 </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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn