Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-17
3
Medium Priority
?
283 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 143

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 143

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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

972 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