Re: Carriage returns in a field

From: Date: Mon, 26 Apr 2004 15:01:54 +0000
Subject: Re: Carriage returns in a field
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-184658@lists.php.net to get a copy of this message
From: "Brian Dunning" <brian@briandunning.com> > I am using a <textarea> entry field and I want returns to be preserved > when that form output is shown on a page later. Currently returns are > not being preserved: they just output as a space so the text is all one > big paragraph. > > 1) Do I need to do anything special when I write the <textarea> to > mysql, and Just escape any quotes in the data using mysql_escape_string(), addslashes() or ensuring you have magic_quotes_gpc enabled. > 2) Do I need to do anything special when I output the query result to > preserve the returns that were typed? The newlines are preserved, but browsers do not render newlines, only HTML. So you need to convert the newlines to <br /> tags. nl2br() is made just for this. Also, remember that if you ever want to "redisplay" this data back into a textarea (like for editing), be sure to run htmlentities() on it first. ---John Holmes...

« previous php.general (#184658) next »