How to retain multiple spaces and wrap text styles when submitting a form, form line feed
The requirement is that the user can block sensitive words when submitting a form. Sensitive words are the same as ciku.txt on the server end. sensitive words are connected by "|", for example, "g | c | a". When a form is submitted, sensitive words are replaced,More importantly, you must keep multiple spaces and line breaks entered by users in the form text field and output them as they are.The php code is as follows:
1 <? Php 2 header ("Content-type: text/html; charset = UTF-8"); 3 if ($ _ POST) {4 $ pattern = array (5 '//', // space 6 '//' At the half-width corner, // space 7 '/\ r \ n/' At the full-width corner, // line break under window 8'/\ n /', // line break 9 in Linux and Unix); 10 $ replace = array ('& nbsp;', '& nbsp;', '<br/> '); 11 $ message = preg_replace ($ pattern, $ replace, $ _ POST ['message']); 12 $cikustr1_file_get_contents('ciku.txt '); 13 $ cikuArr = explode (' | ', $ cikuStr); 14 $ liuyan = str_replace ($ cikuArr, "**", $ Message); 15 echo 'your message is: <br> '. $ liuyan; 16} 17?>
1 <! -- This is the form page code -->
2 <body> 3 <form name = "message_board" id = "message_board" method = "post" action = "timu. php "> 4 <textarea name =" message "id =" message "cols =" 50 "rows =" 10 ">
5 "http://www.cnblogs.com/phpdream/" --- Yong zhiquan 6 </textarea> <br/> 7 <input type = "submit" value = "submit message" id = "submitMessage" onclick =/> 8 </form> 9 </body>
The effect is as follows: