Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    29
    Thanks
    7
    Thanked 0 Times in 0 Posts

    how to stop "nl2br abuse"

    I love the nl2br thingy for PHP on my site, which is a community site, for new lines. But is there any way to stop the abuse of using new lines?

    for example:

    Code:
    hello
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    goodbye
    instead of

    Code:
    hello
    
    goodbye
    I've had a user go all the way to almost 3 pages of white space until I had to ban him myself... the only solution I've been able to think of is using a JS maxlength to limit the number of characters.

    any more suggestions?

    thanks

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Give this function a shot... use it in place of nl2br():
    PHP Code:
    function nl2br_safe$string )
    {
        
    $string str_replace( array( "\r\n""\r" ), "\n"$string );
        
    $string preg_replace'/\n{3,}/'"\n\n"$string );
        return 
    nl2br$string );

    Last edited by kbluhm; 02-28-2008 at 04:55 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •