[英]how to split a long text from database to show it as different paragraphs in php?
I have a string with line breaks in my database,i want to split this and show it as paragraphs in my web page here is my text in my database: 我的数据库中有一个带有换行符的字符串,我想将其拆分并显示为网页中的段落,这是数据库中的文本:
My first paragraph my second paragraph my third paragraph
I want to show this in my web page as 我想在我的网页上显示为
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 actually has a function for this: nl2br
. Php实际上具有此功能: nl2br
。 So you can say echo nl2br($str);
所以你可以说echo nl2br($str);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.