Convert new lines to paragraphs


/ Published in: PHP
Save to your folder(s)

Turns /n to and /n/n to </p><p>

Usage:
echo stripslashes(nl2br(nls2p($text)));


Copy this code and paste it in your HTML
  1. function nls2p($str) {
  2. $str = str_replace('<p></p>', '', '<p>'
  3. . preg_replace('#([
  4. ]\s*?[
  5. ]){2,}#', '</p><p>', $str)
  6. . '</p>');
  7. return $str;
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.