Thread: nl2br()

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

    Join Date
    Mar 2000
    Posts
    26
    Rep Power
    0
    Hi,

    I have a textarea in my form with the database field schema corresponding to it defined as longtext. My problem is that the information I am entering into the textarea has to be entered using <br> tags.

    For example:

    I am making entries of possible majors in the textarea. So I have to type in...

    <br>Accounting
    <br>Computer Science
    <br>Engineering

    ... to make everything print out in a separate line. I have been told there's an easier way to do this -- by using the nl2br() function in PHP.

    Does anyone know about this? How is it implemented and how does it work?

    Any help is much appreciated since I don't want my data entry person wasting time with <br> tags for every new line.

    Thanks,
    Sonya
  2. #2
  3. 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
    18
    In the script where you process the form, before entering in the database just do:

    $now_br=nl2br($text_area_variable_name);

    and insert the $now_br variable into the table
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    26
    Rep Power
    0
    Thanks Rod, makes sense.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    1
    Rep Power
    0
    Another way is ofcourse to use the nl2br() AFTER a MySql fetch, before you are going to display it, like:

    $arr = nl2br($row->something);
    echo "$arr";

    This leaves the database free of html tags, which makes later editing of the post less anoying (especially in longer text files)




    ------------------

Similar Threads

  1. run fortune and add nl2br and htmlentities
    By edman007 in forum PHP Development
    Replies: 1
    Last Post: February 11th, 2004, 08:48 PM
  2. nl2br() and why its my problem
    By BuddyPickle in forum PHP Development
    Replies: 11
    Last Post: August 27th, 2003, 04:19 PM
  3. Realtime Output w/ nl2br() and UNIX Command
    By sn3ak3rp1mp in forum PHP Development
    Replies: 1
    Last Post: March 23rd, 2003, 03:44 PM
  4. dynamic nl2br (fixed the thread)
    By myg- in forum PHP Development
    Replies: 0
    Last Post: July 3rd, 2002, 09:02 AM
  5. nl2br() and XHTML output question
    By willc in forum PHP Development
    Replies: 4
    Last Post: April 19th, 2002, 01:14 PM

IMN logo majestic logo threadwatch logo seochat tools logo