SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    I am sure this one is pretty simple. When I enter info to my database it is not showing the line breaks. It all runs together in a paragraph. How do I fix this? Users enter some data so I want to make this automatic.
    Thanks

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm assuming you are talking about textareas in a form? Then use the attribute/value pair wrap="hard".

    Example:

    <textarea name="longDescription" rows="15" cols="15" wrap="hard">

    And, don't forget to parse your string to addslashes before putting it into the database:

    $longDescription = addslashes($longDescription);

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    umm...I mean when I take the info out of my database, it's bunched together and it ignores the line breaks.
    I am taking the info out of the database and trying to replace the \n's with an HTML line break

    $info = ereg_replace("\n\n","<P>",$info);

    But I am also using addslashes so it just adds more slashes on to the info.

    $info = addslashes($info);

    Output:
    Testing! \\n\\n Testin!!

    Where there should be breaks not the \\n\\n

  4. #4
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't want to add slashes when pulling from a database, you want to add them when putting it in. When pulling it out, right before you display the info, use
    PHP Code:
    $info stripslashes($info); 
    Then, you can also convert new lines to breaks automatically.
    PHP Code:
    $info nl2br($info); 
    should do it. It will add a <br> everytime it encounters a \n and two <br>'s = a <p>, so that should do it. If you prefer <p>'s to two <br>'s, simply do
    PHP Code:
    $info str_replace("<br><br>","<p>",$info); 
    Hope this helps.
    Last edited by tubedogg; Jul 8, 2001 at 06:18.
    Kevin

  5. #5
    SitePoint Enthusiast lieblick's Avatar
    Join Date
    Jun 2001
    Location
    Tallahassee, FL
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm having the same problem and this problem is proving to be more difficult than anticipated!
    Last edited by lieblick; Jul 7, 2001 at 15:07.
    Vendor Ratings, Coupons & Specials:
    http://www.outcrier.com
    My Personal Site:
    http://www.epock.com


Bookmarks

Posting Permissions

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