Solved

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

Posted on 2007-11-17
3
275 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change password links 7 72
PHP Healthcheck 2 81
Paypal 502 Error 3 62
xampp tool 12 21
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

948 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

17 Experts available now in Live!

Get 1:1 Help Now