note 50585 deleted from function.nl2br by googleguy
| From: | googleguy@php.net | Date: | Thu, 13 Jun 2013 11:08:01 +0000 |
| Subject: | note 50585 deleted from function.nl2br by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195165@lists.php.net to get a copy of this message | ||
Note Submitter: freedman AT freeformit . com
----
here's a modified version that allows the addition of style tags to the <p> marker
function nl2p($str,$addtag='') {
return str_replace('<p'.$addtag.'></p>', '',
'<p'.$addtag.'>' . preg_replace('#\n|\r#',
'</p>$0<p'.$addtag.'>', $str) . '</p>');
}
$x = "abc\ndef"
echo nl2p($x); // outputs <p>abc</p>\n<p>def</p>
echo nl2p($x,' style="text-align:justify"');
// outputs <p style="text-align:justify">abc</p>\n<p
style="text-align:justify">def</p>