Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的数据库中有一个带换行符的字符串,我想将其拆分并在我的网页中显示为段落,这是我在数据库中的文本:
My first paragraph my second paragraph my third paragraph
我想在我的网页中显示为
<? $str = 'My first paragraph my second paragraph my third paragraph'; $newstr = str_replace('\n','<br>',$str); echo $newstr; ?>
PHP 实际上有一个功能:nl2br. 所以你可以说echo nl2br($str);
nl2br
echo nl2br($str);