如何在textarea中显示新行?

时间:2012-10-05 16:06:26

标签: php textarea

我正在从textarea向MySQL数据库添加文本。 所有换行都转换为\ r \ n 我可以使用下面的scipt在html中正确地显示新行:

function solver_nl2br($e){
  $output = str_replace("\\r\\n", "<br/>", $e);
  return $output;
}

但是当我尝试在textarea中编辑文本时,我只能看到\r\n而不是新行。

我可以使用什么功能在textarea中显示新行而不是换行符?

3 个答案:

答案 0 :(得分:2)

试试这个,

  $output = nl2br(htmlenitites($e));

答案 1 :(得分:1)

使用原生函数nl2br()。它将捕获更多情况:(\ r \ n,\ n \ r,\ n和\ r \ n)。仅供参考:新行PHP_EOL也有常量。您希望代码在可能的情况下在Windows或Linux上运行良好。

答案 2 :(得分:0)

试试这个:

$output = str_replace("\\r\\n", "\n", $e);
相关问题