#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    20
    Rep Power
    0
    When submittin a form, is there a way to change linebreaks to a <BR>? I know you can use ereg_replace() to replace certain characters, or set of characters, but how to specify a line break?!?

    Thanks in advance

    ------------------
    ---------
    Lanny
    dtm
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    20
    Rep Power
    0
    Thanks! There's a function for everything. Should've guessed.



    ------------------
    ---------
    Lanny
    dtm
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by immortal:
    When submittin a form, is there a way to change linebreaks to a <BR>? I know you can use ereg_replace() to replace certain characters, or set of characters, but how to specify a line break?!?

    Thanks in advance

    [/quote]


    nl2br() is known to be quite buggy. i have had trouble with it in the past and so have others i have spoken to.

    I suggest you use str_replace().
    ie.
    $var = str_replace("n","<br>",$var);

    Good luck
    Basil
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    20
    Rep Power
    0
    With regards to the buginess of nl2br(), is there the same problem with addslashes()??

    Thanks,


    ------------------
    ---------
    Lanny
    dtm
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    I've never had a problem with nl2br(). What's the bug?

    I *have* actually stopped using it, though, since I've switched to XHTML. <BR> won't do anymore. Now it's <br />.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by immortal:
    With regards to the buginess of nl2br(), is there the same problem with addslashes()??

    Thanks,


    [/quote]

    nl2br used to cut off characters every time i used it, and anyone i asked about it on IRC said it was buggy for them too. they mightve fixed it in php4 or something i dunno. sometimes i'be had trouble with addslashes too, a couple of times i used it, it used to add 2 or 3 sets of slashes rather than just 1. just use str_replace() in the format i used above for that too if u need to.

    Basil

  14. #8
  15. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Multiple backslashes are caused by using addslashes when magic_quotes is turned on.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    You're right, Rod K. I don't think nl2br() or addslashes() is buggy. The problem is if you double-use them or use magic-quotes with them. If you're using magic-quotes, you need to pass the strings through stripslashes() before calling nl2br().
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    20
    Rep Power
    0
    On a related subject concerning line breaks. How would you accomplish this?

    I have a form for users to input data. I desire to change newlines to <BR>, store in DB, and then display this text on another page. My issue is that I do not trust my users, so I had called the function htmlentities on the string before displaying it. Of course this disabled the <BR>'s when parsed by the browser. So in summary, can you easily display a string with all html entities disabled except for <BR>'s.

    Thanks
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    30
    Rep Power
    15
    For me personally str_replace(); worked the best for me, but I haven't heard about any bugginess with nl2br()either. *my 2 cents*
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    Before saving to the DB, run it through addslashes() [and trim(), if necessary].

    Then save.

    When displaying, first call htmlentities() and THEN nl2br(). In otherwords, don't store the <BR>'s in the database.

    (1: It's generally bad style to store HTML in the database anyway and 2: You really should be using XHTML anyway. Use <br /> instead of <BR>.)

Similar Threads

  1. changing cursor....
    By DuncanH in forum HTML Programming
    Replies: 2
    Last Post: January 31st, 2009, 07:39 AM
  2. changing cursors for maps
    By gsoper in forum HTML Programming
    Replies: 1
    Last Post: February 8th, 2004, 06:34 AM
  3. Changing video resolution from 1280 X 1024 to 1024 X 768
    By linh in forum Visual Basic Programming
    Replies: 4
    Last Post: January 21st, 2004, 01:46 PM
  4. WHM account creation error messages on RH
    By borisbaloney in forum Linux Help
    Replies: 0
    Last Post: December 16th, 2003, 06:54 PM
  5. Constant changing value then changing back
    By Calbrenar in forum PHP Development
    Replies: 2
    Last Post: September 9th, 2003, 09:34 AM

IMN logo majestic logo threadwatch logo seochat tools logo