Page 1 of 1

How <br>'s can be inserted?

Posted: Thu May 02, 2002 6:25 am
by dethron
Hi all;

the problem, I have , has an easy solution, I think.

I have a test area in my code..

Code: Select all

<textarea name="notes" cols=60 rows=10></textarea>
And when something submitted to this form, and added to a table (akyor) via following code.

Code: Select all

$result = mysql_query ("INSERT INTO akyor (NOTES, DATE, TIME)
	                VALUES ('$notes', '$str_date', '$str_time')              ");
The problem is that, when I displayed these notes in a html file, the browser displays them continuously; I mean when I use <enter> and start a new line in submitted text, in html file, there is no such a new line.

I know the solution is easy, but I can not find a way to replace <enter>'s with <br>'s.

Thanx all.

Posted: Thu May 02, 2002 6:36 am
by samscripts

New Lines to <BR>

Posted: Thu May 02, 2002 6:31 pm
by riley
The only thing I have against the new line to br (nl2br) is during the edit process (If you edit with this in place you create unwanted <br>s , or you have to allow them into the edit text box which takes explaining for non HTML programers) so I found this regular expression replacement works great.

just create a var from your database results.

$var = preg_replace("/(\015\012)|(\015)|(\012)/","<br/>",$var);

It looks for hard returns from your text and inputs the break automatically.

Posted: Thu May 02, 2002 10:03 pm
by jason
Actually, you don't need to do that.

Just use nl2br() on output. Don't store the data in the database with the <br />'s, just use it on output of the data.

Posted: Fri May 03, 2002 1:55 pm
by dethron
thanx, it easy and very nice...
I LOVE PHP

What's the difference...

Posted: Sat May 04, 2002 4:07 am
by sweahe
..between <br> and <br /> ?

/Andreas

Re: What's the difference...

Posted: Sat May 04, 2002 7:39 am
by twigletmac
sweahe wrote:..between <br> and <br /> ?
<br> is HTML and <br /> is XHTML.

Mac