ariestav
asked on
How to insert <p> tags into content submitted via <textarea> input?
So, I am aware of all the really nifty (and free) text editor modules that exist out there. While I could use those to simply my task, all I really want to do is add <p> tags to blank line breaks for content that is typed into a <textarea> input element.
So for example, when a user submits the following into the <textarea>:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam.
Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh.
I would want the HTML that is stored in my database to exist as this:
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam.</p>
<p>
Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh.
</p>
I'd like to be able to handle this on the server using PHP. I'm working with a MySQL database.
Thank you!
So for example, when a user submits the following into the <textarea>:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam.
Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh.
I would want the HTML that is stored in my database to exist as this:
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam.</p>
<p>
Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh.
</p>
I'd like to be able to handle this on the server using PHP. I'm working with a MySQL database.
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried these both, but they did not work.
Hielo: Empty paragraph tags are inserted on blank lines. What I originally asked was how I could make this:
Hello World
A new message
Be stored as this:
<p>Hello World</p><p>A new message</p>
But with your code, the message is stored like this:
<p>Hello World</p><p></p><p>A new message</p>
When the user hits the enter key twice I want to assume that they would like to begin a new paragraph. If the user hits the enter key once, they that is really just a soft return as displayed in the <textarea> tag.
How can I avoid placing the '<p></p>' set where blank lines exist in the <textarea>?
Thanks!
Hielo: Empty paragraph tags are inserted on blank lines. What I originally asked was how I could make this:
Hello World
A new message
Be stored as this:
<p>Hello World</p><p>A new message</p>
But with your code, the message is stored like this:
<p>Hello World</p><p></p><p>A new message</p>
When the user hits the enter key twice I want to assume that they would like to begin a new paragraph. If the user hits the enter key once, they that is really just a soft return as displayed in the <textarea> tag.
How can I avoid placing the '<p></p>' set where blank lines exist in the <textarea>?
Thanks!
ASKER
Thank you very much for your time and help in this question. I ended up using bluetaraka's solution, but tweaked the string to replace to:
"\r\n\r\n"
to replace blank line.
Thanks!
"\r\n\r\n"
to replace blank line.
Thanks!
ASKER