PHP method to remove slashes when submitting a form

墨辰丷
Release: 2023-03-28 10:12:02
Original
1457 people have browsed it

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[&#39;submit&#39;])) {
        //this a "test",5.3.8不自动加斜杠,我测试时是这样的
        echo "原型输出:".$_POST[&#39;str&#39;]."<br/>";
        echo "转换实例:".htmlspecialchars($_POST[&#39;str&#39;])."<br/>";
        echo "删除斜线:".stripslashes($_POST[&#39;str&#39;])."<br/>";
        echo "删除斜线和转换实体:".html2Text($_POST[&#39;str&#39;])."<br/>";
      }
      function html2Text($input) {
        return htmlspecialchars(stripslashes($input));
      }
    ?>
    <?php
      $str = "<font color=&#39;red&#39; 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>
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!