0

I want to show this line to the end when go to submit texarea , for save little data i use txt db and i have problem because the line with \n no get replace this character

For example :

$replace=str_replace("\n","<br>",$val);
$replace=str_replace("\r","<br>",$val);
$replace=str_replace("\n\r","<br>",$val);

Replace \n by <br> but inside the text no see only line i see this

data1,data2,data3,data4,data5<br>
hello
<br>
yes
<br>

And this it´s bad because i need show all in only line

Thank´s Regards !!!

4

3 回答 3

2

如果我理解得很好,您尝试用\nHTML替换<br>? 如果是,可以使用PHP的nl2br函数:http: //php.net/manual/en/function.nl2br.php

于 2013-08-14T13:54:07.837 回答
0

曾经考虑过使用:

echo nl2br($Val);

这使您的代码比查看更优雅:

$replace=str_replace("\n","<br>",$val);
$replace=str_replace("\r","<br>",$val);
$replace=str_replace("\n\r","<br>",$val);

因为 nl2br 完全按照您的str_replace线路所做的工作,并使其更容易。

这会将所有换行符格式转换为 HTML<br>

于 2013-08-14T13:54:47.777 回答
0

尝试这个:

$replace=str_replace("\\\n","<br>",$val);
$replace=str_replace("\\\r","<br>",$val);
$replace=str_replace("\\\n\\\r","<br>",$val);

例如,\n 发送文字字符 n。但是,\\n 被解释为 \(文字字符“\”)和 \n(文字字符“n”)或全部解释为文字“\n”

于 2013-08-14T13:57:07.490 回答