PHP: Getting line breaks in form textarea data _ PHP Tutorial

Source: Internet
Author: User
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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.