Solved

textarea in php

Posted on 2008-06-16
7
728 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 count occurrences of each item in an array.

760 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

20 Experts available now in Live!

Get 1:1 Help Now