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

巴扎黑
Release: 2023-03-10 20:44:01
Original
1326 people have browsed it

The requirement is: 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". The sensitive words are replaced when submitting the form. More importantly, the form text needs to be maintained The multiple spaces and line breaks entered by the user in the field are output as they are. php code is as follows:

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

The screenshot of the effect is as follows:

The above is the detailed content of How 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!