Home  >  Article  >  Backend Development  >  PHP example: example of special character processing function

PHP example: example of special character processing function

WBOY
WBOYOriginal
2016-07-25 08:52:18710browse
This article introduces several examples of PHP functions for processing special characters, including strip_tags, htmlspecialchars, addslashes, etc. Friends in need can refer to it.

Share the usage of special character processing functions in PHP, including the usage of strip_tags, htmlspecialchars, addslashes, etc. Code:

<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 />";
        ?>Try Again<?php
      }
      if ($_POST['submitted'] != "yes"){
        ?>
        <form action="index.php" method="post">
          <p>例子:</p>
          <input type="hidden" name="submitted" value="yes" />
          您的名字: <input type="text" name="yourname" maxlength="150" /><br />
          <input type="submit" value="Submit" style="margin-top: 10px;" />
        </form>
        <?php
      }
    ?>
  </div>
</body>
</html>


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