Solved

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

Posted on 2007-11-17
3
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

739 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