Solved

textarea in php

Posted on 2008-06-16
7
729 Views
Last Modified: 2013-12-13
Hi
i have a textarea in html to let people create text or memo..
i declared in mysql as varchar(255)..
to put the info into textarea is fine when i add a record..
but when i view it it comes all in one big line not as paragraph
how i can make my text looks as paragraph like textarea
0
Comment
Question by:asaidi
7 Comments
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 50 total points
ID: 21792039
use nl2br function for output http://www.php.net/nl2br
0
 
LVL 2

Assisted Solution

by:ayus80
ayus80 earned 150 total points
ID: 21792041
use this code
<?

echo nl2br($textmemo);

?>

Open in new window

0
 

Accepted Solution

by:
asimzeeshan earned 100 total points
ID: 21792049
First of all varchar(255) is not a good idea. It will restrict your ability to add more content. Try changing it to TEXT which can hold much larger amount of data.

Use PHP's nl2br() function to convert new line characters to <BR> tags. This will preserve the hard returns entered in the text area.


suppose form's textarea name is "my_text" so try doing this

$my_text = nl2br($_POST['my_text']);

Open in new window

0
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.

 
LVL 6

Assisted Solution

by:psychic_zero
psychic_zero earned 100 total points
ID: 21792098
You can use htmlspecialchars and nl2br function in PHP.
* htmlspecialchars is to convert special characters to HTML entities
* nl2br is to inserts HTML line breaks before all newlines in a string

This is the sample of getting the text area field:

$memo = nl2br(htmlspecialchars($_POST["txtmemo"]));

It will convert the input string inside the text area to HTML coded string so that the text will look like
paragraph.
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 100 total points
ID: 21792107
@asimzeeshan;

nl2br is an output function, so should not be applied on $_POST['my_text']  befor entering the text in the database.

In addition to hernst42's code, I would add htmlspecialchars as well:

<?php echo nl2br(htmlspecialchars($textmemo));?>
0
 

Author Comment

by:asaidi
ID: 21792310
Hi
i changed my field from varchar to text..
and i added in my form
$lessons = nl2br(htmlspecialchars($_POST['lessons']));
but there i sno <br> the line is not <br> automatically i must return to get into the new line
0
 
LVL 2

Assisted Solution

by:ayus80
ayus80 earned 150 total points
ID: 21801174
asaidi,
for sent value using $_POST['lesson'], you no need to use nl2br.

Use nl2br when you call data from data...

example:
<? echo nl2br($row['dblesson']); ?>

Open in new window

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
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.

867 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

22 Experts available now in Live!

Get 1:1 Help Now