Home > Article > Backend Development > PHP text style implementation code that retains multiple spaces and line breaks
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( '/ /', //半角下空格 '/ /', //全角下空格 '/\r\n/',//window 下换行符 '/\n/', //Linux,Unix 下换行符 ); $replace = array(' ',' ','<br />'); $message=preg_replace($pattern, $replace, $_POST['message']); $cikuStr=file_get_contents('ciku.txt'); $cikuArr=explode('|',$cikuStr); $liuyan=str_replace($cikuArr, "**",$message); echo '您的留言是:<br>'.$liuyan; } ?>
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>
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!