How <br>'s can be inserted?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

How <br>'s can be inserted?

Post 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.
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Post by samscripts »

User avatar
riley
Forum Commoner
Posts: 45
Joined: Thu May 02, 2002 6:31 pm

New Lines to <BR>

Post 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.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

thanx, it easy and very nice...
I LOVE PHP
sweahe
Forum Commoner
Posts: 52
Joined: Sat May 04, 2002 4:07 am
Location: Växjö, Sweden

What's the difference...

Post by sweahe »

..between <br> and <br /> ?

/Andreas
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: What's the difference...

Post by twigletmac »

sweahe wrote:..between <br> and <br /> ?
<br> is HTML and <br /> is XHTML.

Mac
Post Reply