0

G'Day

I have a script that was created from dreamweaver and I do not know much about the nl2br. I Simply want to format the text area when the user creates a new paragraph...

I know the correct function is nl2br() but not how to implement it.

The textarea is description.

i.e.

Yada Yada Yada

Yada Yada Yada

Yada Yada Yada.

The code attached is an edited version of the whole code.

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO attendance (file_ref, attendance, author, attendance_with_name, `attendance_with_company`, `date`, time_commenced, time_completed, `description`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",

GetSQLValueString($_POST['description'], "text"));

<td><textarea name="description" cols="80" rows="20" size="500" ></textarea></td>

Can anyone help?

Thanks

1
  • Its hard to understand what your asking. If you use nl2br when outputting to the textarea it will show the <br /> tags in the box, also dont forget to use the htmlentities function Jan 29, 2012 at 10:09

2 Answers 2

0

When a user presses the return key while typing into the textarea, the carriage return is stored as a \n or \r character. this is stored in your mysql database, then once you want to display it (in a p element for example) you would do something like:

echo "<p>" . nl2br($text) . "</p>";

All of the \n and \r characters are converted to <br/> tags

0

Whenever you want to store text area contents to database, do it like this :

$text = nl2br($_POST['yourTextArea']);

And then insert it in your database.
But whenever you want to show your saved text from database to a text area, do it like this:

<textarea name="description" ><?php echo(strip_tags($text)); ?></textarea>  

strip_tags() will prevent showing <br /> in your text inside text area.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.