PHP method to retain text styles with multiple spaces and line breaks when submitting a form

墨辰丷
Release: 2023-03-27 09:04:01
Original
1598 people have browsed it

The following editor will bring you a method to retain the text style of multiple spaces and line breaks when submitting a form in PHP. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

The requirement is: The function to block 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 implementation of Form submissionData verification processing function method

Solution to PHP form processing Form submissionMultiple input tags with the same name attribute value

python SimulateForm submissionLogin library

The above is the detailed content of PHP method to retain text styles with multiple spaces and line breaks 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!