...

View Full Version : Text area new paragraph



macleodjb
06-20-2009, 01:37 AM
I'm curious if i have a text area that i will be writing in, is it possible to detect a seperation in paragraphs or new lines?

For instance


This is my first paragraph This is my first paragraph This is my first paragraph This is my first paragraph This is my first paragraph

This is my second paragraph This is my second paragraph This is my second paragraph This is my second paragraph


Now what i want to do is just insert a <br> tag whenever there is a new line.

I don't really want to use a RTE. But if this cannot be done then i will do so.

Thanks in advance.

Dhuan
06-20-2009, 02:56 AM
$textarea = str_replace(PHP_EOL,'<br>',$textarea);


That should get the job done...

Fou-Lu
06-20-2009, 11:00 AM
PHP has a built in function for this called nl2br. It inserts a <br /> (or <br> if its running old school) I believe its after the \n.


Insert text

on a new line.

filtered through nl2br would become:


Insert text<br />
<br />
on a new line.

terier
06-20-2009, 01:14 PM
Interesting... didn't know about nl2br... you never stop learning from others :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum