Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

textarea in php

Posted on 2008-06-16
7
Medium Priority
?
736 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
[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
7 Comments
 
LVL 48

Assisted Solution

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

Assisted Solution

by:ayus80
ayus80 earned 600 total points
ID: 21792041
use this code
<?
echo nl2br($textmemo);
?>

Open in new window

0
 

Accepted Solution

by:
asimzeeshan earned 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Assisted Solution

by:psychic_zero
psychic_zero earned 400 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 400 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 600 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

Independent Software Vendors: 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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
Suggested Courses

604 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