Home >Backend Development >PHP Tutorial >PHP gets line breaks in form textarea data_PHP tutorial

PHP gets line breaks in form textarea data_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:34:341006browse

Test page code:

Copy code The code is as follows:





< title>PHP gets line break problem in form area data


$content=empty($_POST[' content'])?null:trim($_POST['content']);
if(!empty($content))echo str_replace("r",'rl',nl2br($content));
echo "r".'
----------Separating line----------------------'." r";
if(!empty($content))echo str_replace("n",'nl',nl2br($content));
echo "n".'
-- --------Separating line---------------------'."n";
if(!empty($content)) echo str_replace("r",'rl',str_replace("n",'nl',nl2br($content)));
echo "r".'
------ ----Separating line----------------------
'."n";
echo 'hello'."n ".'boys!';
echo 'hello'."r".'boys!';
?>




< ;input type="submit" value="Submit" />




After opening it in the browser, enter in the form:

PHP gets line breaks in form textarea data_PHP tutorial

After pressing submit, the results displayed in the browser are as follows:

PHP gets line breaks in form textarea data_PHP tutorial

You can see the following results in the notepad:

PHP gets line breaks in form textarea data_PHP tutorial

It can be seen from the above results:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322401.htmlTechArticleTest page code: Copy the code as follows: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="ht...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn