_php tips for getting a new line in the form textarea data from PHP

Source: Internet
Author: User
To test the page code:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>php gets the line-wrapping problem in the form area data </title>
<body>
<?php
$content =empty ($_post[' content ')? Null:trim ($_post[' content '));
if (!empty ($content)) echo str_replace ("\ r", ' RL ', NL2BR ($content));
echo "\ r". ' <br/>----------Split Line----------------------'. ' \ r ";
if (!empty ($content)) echo str_replace ("\ n", ' NL ', NL2BR ($content));
echo "\ n". ' <br/>----------Split Line----------------------'. ' \ n ";
if (!empty ($content)) echo str_replace ("\ r", ' RL ', str_replace ("\ n", ' NL ', NL2BR ($content)));
echo "\ r". ' <br/>----------Split Line----------------------<br/> '. ' \ n ";
The echo ' Hello '. \ n '. ' Boys! ';
The echo ' Hello '. \ r '. ' Boys! ';
?>
<form action= "textareanl.php" method= "post" enctype= "Multipart/form-data" >
<textarea name= "Content" cols= "rows=" 6 "></textarea>
<br/>
<input type= "Submit" value= "submitted"/>
</form>
</body>

After opening in the browser, enter in the form:

When submitted, the results are displayed in the browser as follows:

In Notepad cocoa see the following results:

From the above results are visible:

The 1.PHP function nl2br () inserts an HTML newline character before each new line (\ r \ n) in the string:<br/>;
2.Windows line wrapping is (\ r \ n);
3. In Notepad, \ r or \ n has the function of wrapping;

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.