PHP retrieves line breaks in form textarea data

Source: Internet
Author: User
Tags php form
Nothing left to worry about. I saw an article on php form conversion textarea line break on the Internet. After reading the article, I feel that some information in this article is not accurate based on my past experience... as a result, I personally obtain form data from php.

Nothing left to worry about. I saw an article on php form conversion textarea line break on the Internet. After reading the article, I feel that some information in this article is not accurate based on my past experience... as a result, I personally obtain form data from php.

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;

, Hong Kong Server rental, server space, server space

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.