Home > Backend Development > PHP Tutorial > A simple method for php to process special characters entered in a form

A simple method for php to process special characters entered in a form

巴扎黑
Release: 2016-11-21 10:36:28
Original
1049 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> 
<?php 
if ($_POST[&#39;submitted&#39;] == "yes"){ 
$yourname = $_POST[&#39;yourname&#39;]; 
$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[&#39;submitted&#39;] != "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>
Copy after login


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