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

巴扎黑
巴扎黑Original
2016-11-21 10:36:281052browse

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>


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