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!';
?>
After opening it in the browser, enter in the form:
After pressing submit, the results displayed in the browser are as follows:
You can see the following results in the notepad:
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;
http://www.bkjia.com/PHPjc/322401.htmlwww.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