0

Hey,

I have a textfield and before I insert it into the database I run the function nl2br();

It works grand add's <br>'s at brake lines...

However when I output it back into a textfield to edit it and update the record it had the <br>'s? Not a brake line...

Help!

Dan

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by diafol
0

Well of course it will. The textarea will show the whole string, including any html you've put into it.

Keep the DB version clean (newlines only).

echo nl2br version to the page, for basic html output.
echo clean version to the textarea for editing.

0

Well of course it will. The textarea will show the whole string, including any html you've put into it.

Keep the DB version clean (newlines only).

echo nl2br version to the page, for basic html output.
echo clean version to the textarea for editing.

Will it keep the brake lines though? Even if you keep it clean in the database?

Dan

0

What do you mean keep it?
You're only using this nl2br() to display it on a page right? You're not storing it in any way, are you?

0

What I do is use nl2br() to save the line brakes then inset it into the database...

When when the user edits it it has <br>'s not brake lines... do you get me? Or do I need to call nl2br(); to replace <br> with line brakes?

Dan

1

This is the whole point of keeping clean version in DB, to avoid this mess. Don't save the <br /> at all. Only use nl2br() when you want to display the data in html (which is temporary of course).

<div>
<?php echo nl2br($datafromDB);?>
</div>

and in edit mode:

<textarea><?php echo $datafromDB;?></textarea>

When the data is edited and resubmitted, you just use mysql_real_escape_string() again to store it (no <br /> anywhere near it).

0

OK, if we're solved, click the link below the edit box.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.