Home > Backend Development > PHP Tutorial > A simple way to process special characters entered in a form using PHP

A simple way to process special characters entered in a form using PHP

WBOY
Release: 2016-07-29 09:04:12
Original
985 people have browsed it

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 />";
    ?><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" />
    </form>
    <&#63;php
   }
  &#63;>
 </div>
</body>
</html>

Copy after login

Readers who are interested in more PHP-related content can check out the special topics on this site: "Summary of Usage of PHP Strings", "Summary of Usage of PHP Operations and Operators" ", "Introduction Tutorial on PHP Basic Syntax" and "Summary of PHP Methods to Prevent SQL Injection"

I hope this article will be helpful to everyone in PHP programming.

The above introduces PHP's simple method of processing special characters entered in a form, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template