Home Backend Development PHP Tutorial How to retain text styles with multiple spaces and line breaks when submitting a form

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

Jun 23, 2017 pm 02:11 PM
reserve Multiple how submit form

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                 '/ /',  //半角下空格 6                 '/ /',  //全角下空格 7                 '/\r\n/',//window 下换行符 8                 '/\n/', //Linux,Unix 下换行符 9          );10     $replace = array(' ',' ','<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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement page jump after PHP form submission How to implement page jump after PHP form submission Aug 12, 2023 am 11:30 AM

How to implement page jump after PHP form submission

How to handle user rights management in PHP forms How to handle user rights management in PHP forms Aug 10, 2023 pm 01:06 PM

How to handle user rights management in PHP forms

Python's round() function: retain decimals with specified digits Python's round() function: retain decimals with specified digits Nov 18, 2023 pm 05:35 PM

Python's round() function: retain decimals with specified digits

How to use JavaScript to implement real-time verification of the input box content of a form? How to use JavaScript to implement real-time verification of the input box content of a form? Oct 18, 2023 am 08:47 AM

How to use JavaScript to implement real-time verification of the input box content of a form?

How to use JavaScript to realize the automatic prompt function of the input box content of the form? How to use JavaScript to realize the automatic prompt function of the input box content of the form? Oct 20, 2023 pm 04:01 PM

How to use JavaScript to realize the automatic prompt function of the input box content of the form?

MySQL transaction processing: the difference between automatic submission and manual submission MySQL transaction processing: the difference between automatic submission and manual submission Mar 16, 2024 am 11:33 AM

MySQL transaction processing: the difference between automatic submission and manual submission

PHP form processing: form data query and filtering PHP form processing: form data query and filtering Aug 07, 2023 pm 06:17 PM

PHP form processing: form data query and filtering

Will the Win11 upgrade retain the details of the original software? Will the Win11 upgrade retain the details of the original software? Dec 31, 2023 pm 02:49 PM

Will the Win11 upgrade retain the details of the original software?

See all articles