[thelist] Tiny Problem

Michele Wandrei michele at inthree.com
Tue Oct 15 13:14:15 CDT 2002

> an input area of a form, say a large "textarea" when anyone
makes a carriage
> return {like at the end of a paragraph) and then they send the
> when it renders back from the MySQL table where it's stored,
the carriage
> returns are never present.
> So at the moment when anyone enters any info and want's to end
a paragraph
> and start a new one, it's a case of adding <BR><BR>, is there a
way to get
> around this? (using PHP).

I use the nl2br function to do that (thanks to an older tip from
someone on this list).

To add break tags to text, before inserting the text into the

$text = nl2br($text);

Here's the other half -- if you're going to pull that text out of
the database and edit it, you need to strip the break tags out.
You can add them back again with nl2br before updating the table.

Here's the code I use:

//strip all standard and XHTML-compliant <br> tags
//Used with nl2br function
$text = eregi_replace('<br[[:space:]]*/?[[:space:]]*>', "",

Hope this helps,
Michele Wandrei
inThree Design

More information about the thelist mailing list