note 97643 modified in function.nl2br by danbrown
| From: | danbrown@php.net | Date: | Fri, 30 Apr 2010 12:10:05 +0000 |
| Subject: | note 97643 modified in function.nl2br by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168814@lists.php.net to get a copy of this message | ||
convert multiple new lines to p tags with an optional class assigned to the p tags
<?php
function nl2p($string, $class='') {
$class_attr = ($class!='') ? ' class="'.$class.'"' :
'';
return
'<p'.$class_attr.'>'
.preg_replace('#(<br\s*?/?>\s*?){2,}#',
'</p>'."\n".'<p'.$class_attr.'>', nl2br($string,
true))
.'</p>';
}
?>
--was--
<?php
// convert multiple new lines to p tags
// with an optional class assigned to the p tags
function nl2p($string, $class='') {
$class_attr = ($class!='') ? ' class="'.$class.'"' :
'';
return
'<p'.$class_attr.'>'
.preg_replace('#(<br\s*?/?>\s*?){2,}#',
'</p>'."\n".'<p'.$class_attr.'>', nl2br($string,
true))
.'</p>';
}
?>
http://php.net/manual/en/function.nl2br.php