Php reads textarea row by row and outputs line breaks to textarea

Source: Internet
Author: User
I recently studied discuz and found that many backend settings are filled in with textarea and each row is interesting, avoid wasting too much time on the control issues during the settings. Let's just move on to the code: $ namesn... I recently studied discuz and found that many backend settings are filled in with textarea and each row is interesting, avoid wasting too much time on the control issues during the settings.

Let's just move on to the code:

$names = preg_split('/rn/',$_POST['textarea']);foreach($names as $name){    // todo something eg: echo $name;}

The value is very simple, so the value assignment is not that easy to output line breaks in textarea.

$vals = get_from_mydb();$tmp = '';foreach($vals as $val){    $tmp .= $val.'
';}

What does "" and "" mean, because I won't talk about the time, just go to Baidu GG!

   
  PHP retrieves line breaks in form area data   
 ---------- 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 in the browser and enter

:

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 () is to insert an HTML line break before each new line (rn) in the string:
;
2. in Windows, the line feed is (rn );
3. in Notepad, r or n has the newline function;

Article URL:

Reprint ^ at will, but please attach the tutorial address.

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.