PHP read textarea and output line breaks to textarea

Source: Internet
Author: User
Tags foreach empty split

The code is as follows

$names = Preg_split ('/rn/', $_post[' textarea '));
foreach ($names as $name) {
Todo something Eg:echo $name;
}

The value is very simple, then the assignment, in the TEXTAREA output line break is not so simple

The code is as follows

$vals = Get_from_mydb ();
$tmp = ';
foreach ($vals as $val) {
$tmp. = $val. ' & #13;& #10; ';
}

"and" "is what meaning, because the question of time I don't say, I go to Baidu GG!"

  code is as follows &nbs P;

<! 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>&NBSP
<?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 ";  
Echo ' Hello '." n ". ' Boys! ';  
Echo ' Hello '. R ". ' Boys! '; &NBSP
? > 
<form action= "textareanl.php" method= "post" enctype= "Multipart/form-data" > 
<textarea name= "content" cols= "rows=" 6 "></TEXTAREA>&NBSP;
<br/> 
<input Type= "Submit" value= "submitted"/>&NBSP;
</form> 
</body> 

After opening in the browser, enter the form in the

:

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 (RN) in the string:

;

2.Windows line wrapping is (RN);

3. In Notepad, R or n all have the function of line-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.