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( '/ /', //半角下空格 '/ /', //全角下空格 '/\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 implementation of Form submissionData verification processing function method
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!