我找到了这个..我正在寻找像这样的跨度,因为预定义功能不适用于回声...
function nl2p($string, $line_breaks = true, $xml = true)
{
// Remove existing HTML formatting to avoid double-wrapping things
$string = str_replace(array('<p>', '</p>', '<br>', '<br />'), '', $string);
// It is conceivable that people might still want single line-breaks
// without breaking into a new paragraph.
if ($line_breaks == true)
return '<p>'.preg_replace(array("/([\n]{2,})/i", "/([^>])\n([^<])/i"), array("</p>\n<p>", '<br'.($xml == true ? ' /' : '').'>'), trim($string)).'</p>';
else
return '<p>'.preg_replace("/([\n]{1,})/i", "</p>\n<p>", trim($string)).'</p>';
}
<?php
$text = "Hello.
My name is Geoffrey.";
echo nl2p($text);
?>
谢谢大家:)