PHP obtains the line feed in the form textarea data. Test page code: Copy the code as follows :! DOCTYPEhtmlPUBLIC-W3CDTDXHTML1.0TransitionalENwww.w3.orgTRxhtml1DTDxhtml1-transitional.dtdhtmlxmlnsht test page code:
The code is as follows:
PHP retrieves line breaks in form area data
$ Content = empty ($ _ POST ['content'])? Null: trim ($ _ POST ['content']);
If (! Empty ($ content) echo str_replace ("\ r", 'rl ', nl2br ($ content ));
Echo "\ r ".'
---------- Split line -------------------- '. "\ r ";
If (! Empty ($ content) echo str_replace ("\ n", 'nl ', nl2br ($ content ));
Echo "\ n ".'
---------- Split line -------------------- '. "\ n ";
If (! Empty ($ content) echo str_replace ("\ r", 'rl ', str_replace ("\ n", 'nl', nl2br ($ content )));
Echo "\ r ".'
---------- Split line ----------------------
'. "\ N ";
Echo 'hello'. "\ n". 'Boys! ';
Echo 'hello'. "\ r". 'Boys! ';
?>
Open it in the browser and enter the following in the form:
After you press submit, the browser displays the following results:
In Notepad Coco, you can see the following results:
The preceding results show that:
1. the PHP function nl2br () inserts an HTML line break before each new line (\ r \ n) in the string:
;
2. in Windows, the line feed is (\ r \ n );
3. in Notepad, \ r or \ n have the line feed function;
The pipeline code is as follows :! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns = "ht...