Posted By

jmiller on 10/26/10


Tagged

format new paragraph lines nls2p


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

pytheas


Convert new lines to paragraphs


 / Published in: PHP
 

Turns /n to and /n/n to

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

  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  

You need to login to post a comment.