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
Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
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…

809 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