我想将换行符转换为段落。
例如
$string = "1st paragraph
2nd paragraph
3rd paragraph
";
我想得到,
<p>1st paragraph</p>
<p>2nd paragraph</p>
<p>3rd paragraph</p>
和,
$string = "1st paragraph
2nd paragraph
a line break
3rd paragraph
";
进入,
<p>1st paragraph</p>
<p>2nd paragraph<br/>a line break</p>
<p>3rd paragraph</p>
regex
和有可能reg_replace
吗?或者其他更好的东西 - xpath
?
这个我试过了,还没有结果
echo preg_replace("'/^(.*?)(<br\s*\/?>\s*)+/'", "<p>$1</p>", nl2br($string));