任何人都知道如何在php中将字符串值转换为html格式? 例如:
$string = "Hello World!!
How are you?"
如果我回显$ string,它将显示如下:
Hello World!!How are you?
而不是:
Hello World!!
How are you?
任何方式PHP都可以将$ string转换为html格式?如果我输入:
$string = "Hello World!!
How are you?"
Php会将其转换为:
$string = "Hello World!!<br>How are you?"
答案 0 :(得分:8)
您正在寻找为每个物理换行符序列<br />
,\n
或\r
添加HTML换行符\r\n
的{{3}} ):
\n → <br />\n
\r → <br />\r
\r\n → <br />\r\n
答案 1 :(得分:1)
$string = "Hello World!!
How are you?";
echo nl2br($string);