Solved

Adding <p></p> to a submitted text area

Posted on 2007-11-17
3
274 Views
Last Modified: 2008-02-01
I'm currently making a guest book for a site I'm building at the moment but have hit a problem I can't seem to get past.

I have a text area where a visitor can type their message but when it's submitted and sent to the database it loses all its formatting. So basically all I need it to do is add <p></p> tags where appropriate. Is there a way to do this with php?

I want to keep things simple so don't want a full blown wysiwyg editor with stripped features.

Thank you
0
Comment
Question by:Mr_Splash
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20305141
>it loses all its formatting.
I must assume that you mean the line breaks.
in fact, the data submitted saves the carriage return with \n  , and to display with the html output a line break, you will need to replace that by a <br>.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20305146
please see here:
http://lu.php.net/nl2br
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 250 total points
ID: 20305148
>> So basically all I need it to do is add <p></p> tags where appropriate

Where do you see appropriate to add the <p> tag ??

You can very easily add <br> tags for every new line using the nl2br() function

$text = nl2br($_POST["textarea_name"]);

http://www.php.net/manual/en/function.nl2br.php
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now