Solved

textarea in php

Posted on 2008-06-16
7
730 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

772 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