[thelist] php speicial character conversion and carriage returns

Wade Armstrong wade_lists at runstrong.com
Tue May 7 13:35:43 CDT 2002

on 5/7/02 2:15 AM, kristina at kristina at kfx-design.co.uk wrote:

> List,
> I've created a little form that sends data to a database - one
> element of the form is a text field that has the ability to put alot
> of data into.  One of the requirements of this field is that if
> there is a carriage return its converted to a <br> - The trouble is
> that if the entry is saved and uploaded and then opened to be edited
> and then uploaded.  All the <br>'s multiply....?!?!  - I'm using:
> $description = nl2br("$description");
> What can I do so that it doesn't repeat the carriage returns on a
> re-edit, bearing in mind that if new carriage returns are added they
> will need to upload as such.

I've run into this problem in building content management systems, and have
found that the best way is to not run nl2br() until you're displaying the
data - so it's kept in the db with the raw formatting, line breaks and all.
this makes it easy to display in a <textarea>, and allows you to change your
formatting rules at any time without having "legacy" formatting stuck in the


More information about the thelist mailing list