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

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

WBOY
WBOYOriginal
2016-06-01 12:17:39719browse

textarea

测试页面代码:
复制代码 代码如下:




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或\n均有换行的功能;

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