在php中将字符串值转换为html格式

在php中将字符串值转换为html格式,php,Php,有人知道如何在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?" Ph

有人知道如何在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?" 
$string=“你好,世界!!
你好吗?”
您正在寻找将HTML换行标记添加到每个物理换行序列(
\n
\r
\r\n
)的:

\n→  
\n \r→
\r \r\n→
\r\n
您正在寻找将HTML换行标记添加到每个物理换行序列(
\n
\r
\r\n
)的:

\n→  
\n \r→
\r \r\n→
\r\n
请记住,这只会将回车(输入字符)转换为标签。@Mladen Mihajlovic:不,不会。它将HTML换行符添加到每个物理换行符序列中:
\r\n
\n
\r

\r\n

\n

\r
请记住,这只会将回车(输入字符)转换为
标记。@Mladen Mihajlovic:不,不会。它将HTML换行符添加到每个物理换行符序列中:
\r\n
\n
\r
→ <代码>
\r\n,

\n

\r
\n    →  <br />\n
\r    →  <br />\r
\r\n  →  <br />\r\n
$string = "Hello World!!
       How are you?";
echo nl2br($string);