PHP gets form feed textarea data in the line breaks

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags based code content data echo get html http

Nothing else, see an article on the PHP form conversion textarea line breaks, after reading, based on past experience, I feel some of the information in this article is not accurate ... So I personally php Get a list of newline characters in the data to study

Test page code:

<! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "Content-Type" content = "text / html; charset = utf-8" />
<title> PHP Get Wrap Issues in Form Area </ title>
</ head>
<body>
<? php
$ content = empty ($ _ POST ['content'])? null: trim ($ _ POST ['content']);
if (! empty ($ content)) echo str_replace ("r", 'rl', nl2br ($ content));
echo "r". '---------- Partition line ----------------------'. "r";
if (! empty ($ content)) echo str_replace ("n", 'nl', nl2br ($ content));
echo "n". '---------- Partition 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!';
?>
<form action = "textareanl.php" method = "post" enctype = "multipart / form-data">
<textarea name = "content" cols = "20" rows = "6"> </ textarea>
<br />
<input type = "submit" value = "Submit" />
</ form>
</ body>
</ html>

Open in the browser, enter in the form:

From the above results we can see:

1. The PHP function nl2br () inserts HTML line breaks before each new line (rn) in the string:
2. Wows under the line is (rn);
In Notepad, r or n have the function of line breaks;

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.