Skip to main content
Inspiring
April 6, 2012
Answered

linebreaks with a text field not displaying in results

  • April 6, 2012
  • 1 reply
  • 638 views

i have an input field <textarea name="terms" cols="60" rows="5"><?php echo htmlentities($row_Recordset1['terms'], ENT_COMPAT, 'utf-8'); ?></textarea>

the php is

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form4")) {

  $updateSQL = sprintf("UPDATE think_terms SET terms=%s WHERE termsID=%s",

                       GetSQLValueString($_POST['terms'], "text"),

                       GetSQLValueString($_POST['termsID'], "int"));

the results is

<div class="textblack" id="terms_body"><?php echo $row_Recordset1['terms']; ?></div>

it is all coming out as one block

when the text is inputed it is like this

"The standard Lorem Ipsum passage, used since the 1500s

 

"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "

but when display it comes out like

The standard Lorem Ipsum passage, used since the 1500s "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

i tried the "/n" in the <div class="textblack" id="terms_body"><?php echo $row_Recordset1['terms']; ?></div>

but that didnt work

This topic has been closed for replies.
Correct answer Jonathan_Fortis

<?php echo nl2br($row_Recordset1['terms']); ?>

done it, thanks for the advice

jon

1 reply

Participating Frequently
April 6, 2012

>i tried the "/n" in the <div class="textblack" id="terms_body"><?php echo $row_Recordset1['terms']; ?></div>

"/n" ?  Not sure what you mean. When you hit RETURN on the keyboard, a newline character is inserted. Newlines, carriage returns, etc, are all just whitespace. Remember what HTML does to whitespace?  Try using the nl2br function.

Inspiring
April 7, 2012

i take it the nl2br goes in the results

looking at tutorial is says it can go after the echo so by php is

<?php echo $row_Recordset1['terms']; ?>

<?php echo nl2br $row_Recordset1['terms']; ?>

but this is giving syntax errors

where is it meant to go then?

Jonathan_FortisAuthorCorrect answer
Inspiring
April 8, 2012

<?php echo nl2br($row_Recordset1['terms']); ?>

done it, thanks for the advice

jon