?
Solved

textarea in php

Posted on 2008-06-16
7
Medium Priority
?
735 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
Technology Partners: 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!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 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