Welcome to Server Circle. It's a friendly site and all levels of experience are welcome. Be aware that we use cookies for your login.
Server Circle - Ask questions about Servers and get answers from experts.
Beta (0.83 sec)
Bizarre nl2br and line break formatting

Having studied this page for ages and tried a few functions it seems there's still issues with HTML output, in some cases nl2br outputs two line breaks.

Any ideas ? I'm at a loss !

http://php.net/manual/en/function.nl2br.php
Asked by:
Trinity
2782 points
 Report Abuse
 Share Page - Category: Programming - Tags: Bizarre nl2br and line break formatting
 Enter your response
Please use Pastie.org to paste lengthy code or to fix formatting issues with code
  • Responses in reverse (1)

Try this handy function:

function nl2brStrict($text, $replacement = ' < br / > '){return preg_replace("((\r\n)+)", trim($replacement), $text);}

Remove spaces in the < br / > tag. It's a normal HTML line break.

Response by:
BonoEstente
1464 points


  • Related Questions
About Us : Contact Us : Etiquette : Terms : CDN Failover : ShorterURL : CDN Fallback : © 2013 Server Circle