Home > Backend Development > PHP Tutorial > PHP获取表单textarea数据中的换行问题_php技巧

PHP获取表单textarea数据中的换行问题_php技巧

WBOY
Release: 2016-05-17 09:23:11
Original
1767 people have browsed it

测试页面代码:

复制代码 代码如下:





PHP获取表单area数据中的换行问题


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









在浏览器中打开后,在表单中输入:

PHP获取表单textarea数据中的换行问题_php技巧

按提交后,浏览器中显示结果如下:

PHP获取表单textarea数据中的换行问题_php技巧

 

在记事本可可看到如下结果:

PHP获取表单textarea数据中的换行问题_php技巧

从以上结果可见:

1.PHP函数nl2br()是在字符串中的每个新行(\r\n)之前插入HTML换行符:
;
2.Windows下的换行是(\r\n);
3.在记事本中,\r或 均有换行的功能;

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template