PHP text style implementation code that retains multiple spaces and line breaks

小云云
Release: 2023-03-20 10:12:01
Original
2768 people have browsed it

The function of blocking sensitive words when users submit forms. The sensitive words come from ciku.txt under the same path on the server side. The sensitive words are connected through "|", such as "g|c|a". When submitting the form, the sensitive words are replaced. More importantly, the username in the form text field needs to be maintained. Enter multiple spaces and newline styles and output them as they are. The php code is as follows:


<?php
header("Content-type:text/html;charset=utf-8");
if($_POST){
  $pattern = array(
        &#39;/ /&#39;,  //半角下空格
        &#39;/ /&#39;,  //全角下空格
        &#39;/\r\n/&#39;,//window 下换行符
        &#39;/\n/&#39;, //Linux,Unix 下换行符
     );
  $replace = array(&#39; &#39;,&#39; &#39;,&#39;<br />&#39;);
  $message=preg_replace($pattern, $replace, $_POST[&#39;message&#39;]); 
  $cikuStr=file_get_contents(&#39;ciku.txt&#39;);
  $cikuArr=explode(&#39;|&#39;,$cikuStr);
  $liuyan=str_replace($cikuArr, "**",$message);
  echo &#39;您的留言是:<br>&#39;.$liuyan;
}
?>
Copy after login


1<!--这是表单页面代码--> 
<body>
  <form name="message_board" id="message_board" method="post" action="timu.php">
     <textarea name="message" id="message" cols="50" rows="10" >     
        "http://www.cnblogs.com/phpdream/"---勇往直泉
      </textarea><br/>
     <input type="submit" value="提交留言" id="submitMessage" onclick= />
  </form>
</body>
Copy after login

The screenshot of the effect is as follows:

Related recommendations:

PHP replaces regular punctuation marks with spaces

Example of how to replace regular punctuation marks with spaces in PHP

Summary of various methods of using spaces in html

The above is the detailed content of PHP text style implementation code that retains multiple spaces and line breaks. 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