Home > Article > Backend Development > PHP method to remove slashes when submitting a form
This article mainly introduces the method of removing slashes when submitting forms in PHP, and involves PHP's related skills in filtering elements for page form submissions. Friends in need can refer to the following
The examples in this article describe PHP Implement a method to remove slashes when submitting a form. Share it with everyone for your reference, the details are as follows:
<html> <head> <title>HTML 表单</title> </head> <body> <form action="" method="POST"> 请输入一个字符串: <input type="text" size="30" name="str" value=""> <input type="submit" name="submit" value="提交"><br/> </form> <?php if(isset($_POST['submit'])) { //this a "test",5.3.8不自动加斜杠,我测试时是这样的 echo "原型输出:".$_POST['str']."<br/>"; echo "转换实例:".htmlspecialchars($_POST['str'])."<br/>"; echo "删除斜线:".stripslashes($_POST['str'])."<br/>"; echo "删除斜线和转换实体:".html2Text($_POST['str'])."<br/>"; } function html2Text($input) { return htmlspecialchars(stripslashes($input)); } ?> <?php $str = "<font color='red' size=7>Linux</font><i>Apache</i><u>MySQL</u><b>PHP</b>"; echo strip_tags($str);//删除全部HTML标签 echo "<br/>"; echo strip_tags($str,"<font>");//第二个参数,保留的标签 echo "<br/>"; echo strip_tags($str,"<b><u><i>"); ?> </body> </html>
The above is the entire content of this article, I hope it will be helpful to everyone’s study .
Related recommendations:
php function stripslashes() that deletes the reverse slash added by the addslashes() function
php removes the backslashes added by the addcslashes() function Function stripcslashes()
php adds inverse before some predefined characters in the string slashFunction quotemeta()
The above is the detailed content of PHP method to remove slashes when submitting a form. For more information, please follow other related articles on the PHP Chinese website!