#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    571
    Rep Power
    51

    Carriage Return in Form / Report


    I have a data entry form with a textarea field. If I enter multiple paragraphs, separated by a carriage return, and then view the text in a report, the paragraphs are all run together with no separation.

    However, if I edit the actual record using PHPMySQL, the carriage returns are intact and the text appears as separate paragraphs.

    What would be causing this?

    The text area on the form looks like:
    Code:
    <textarea name="description"  rows=5 wrap=virtual>$description  </textarea>
    The echo to the web page looks like:
    Code:
              $display_description  = $newArray['display_description'];
    
    echo "
    	<strong>Description:</strong><br/>
    	$description
    ";
    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,468
    Rep Power
    653
    It is the line end character(s) being used when the data is entered into the text field. It is probably '\r' or '\r\n'. MySQL understands what those line end characters mean but browsers do not. You need to replace them with <br /> for HTML to know you want a new line.
    Last edited by gw1500se; September 1st, 2018 at 09:20 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    142
    Rep Power
    66
    Apply nl2br() when you output the data in a html context.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2004
    Location
    Boston, MA USA
    Posts
    571
    Rep Power
    51
    Originally Posted by DSmabismad
    Apply nl2br() when you output the data in a html context.
    Perfect! Thank you. I am not sure how I missed this for so long...

IMN logo majestic logo threadwatch logo seochat tools logo