SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member frrogoy's Avatar
    Join Date
    Dec 2003
    Location
    Indiana
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to display text with hard returns

    I am making a page that will display a recipe selected at random from a DB. The ingredients were entered via a textarea with wrap=hard. When I View Source on the output page, the ingredients are all flush left, as entered and stored in the DB. The browser word wraps them though. I have a picture, float right, alongside the ingredients.

    Is there some easy way to display text as it was entered? Can I use a textarea on output without it looking like a form entry area?

    So far, I have built the whole website without tables (except for the buttons Fireworks created). But I am not adverse to using a table, if that is the solution.

  2. #2
    Ensure you finish what you sta bronze trophy John Colby's Avatar
    Join Date
    Aug 2003
    Location
    University of Central England, U.K.
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you not use <pre></pre> around that area in the page layout?
    John
    No electrons were harmed during the creation, transmission
    or reading of this posting. However, many were excited and
    some may have enjoyed the experience.

  3. #3
    SitePoint Member frrogoy's Avatar
    Join Date
    Dec 2003
    Location
    Indiana
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wasn't aware of the <pre> tag. Looks like it restricts you to fixed space (Courier) fonts. But that is certainly an easy solution! I'll try it and see how it looks. Courier is better than the wrapping!

  4. #4
    A Smarter Way to Web! zivo's Avatar
    Join Date
    Aug 2003
    Location
    Chicago
    Posts
    433
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Imbed or interface

    You could imbed the non-breaking space symbol -
    Code:
    &nbsp;
    - or use an interface for entering the text, similar to how I am typing this post.

    mp/m

  5. #5
    Ensure you finish what you sta bronze trophy John Colby's Avatar
    Join Date
    Aug 2003
    Location
    University of Central England, U.K.
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by frrogoy
    I wasn't aware of the <pre> tag. Looks like it restricts you to fixed space (Courier) fonts. But that is certainly an easy solution! I'll try it and see how it looks. Courier is better than the wrapping!
    Then style the <pre> tag. Something like:
    Code:
    pre {
       font-family: verdana, arial, helvetica, sans-serif;
    }
    John
    No electrons were harmed during the creation, transmission
    or reading of this posting. However, many were excited and
    some may have enjoyed the experience.

  6. #6
    SitePoint Member frrogoy's Avatar
    Join Date
    Dec 2003
    Location
    Indiana
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked great John. Thanks for the help!

  7. #7
    SitePoint Member frrogoy's Avatar
    Join Date
    Dec 2003
    Location
    Indiana
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just came across another relevant tip in the PHP tips thread: There is a PHP function that looks like it was designed for this output scenario. nl2br() adds <br /> in front of each new line.
    Frank

  8. #8
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    529
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can use the php function nl2br() which will take line breaks (/n) and convert them to <br />'s when displayed in your html code.

    for example:

    PHP Code:
    print nl2br($_POST["txtTextarea"]); 
    edit: err...nevermind, you found it


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
  •