标签: php html string
我需要将所有新行,回车符和空格转换为HTML标记。我使用字符串替换将\n替换为<br />,并且需要找到一种至少转换空格的方法。
\n
<br />
答案 0 :(得分:0)
nl2br()适用于<br />的新行,但要完成所有操作仍然使用str_replace():
nl2br()
str_replace()
$result = str_replace(array(" ","\n","\r"), array(" ","<br />",""), $string);