PHP and textareas

This is a discussion on "PHP and textareas" within the PHP Forum section. This forum, and the thread "PHP and textareas are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Sep 25th, 2005, 15:11
Up'n'Coming Member
Join Date: Sep 2005
Location: athens
Age: 26
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
PHP and textareas

Hi all,
I have a page which includes a textarea fro the user to submit data in order to be retrieved from Mysql tables

Question: I am confused about the 'wrapping' thing of textareas.
I have tried 'virtual' and 'physical' and nothing seems to work. What I want to do is when the user supplies ,for example, 4 data separated by <ENTER>, the page break not to dissapear, that is, I want

data1
data2
data3
data4

to remain as above and not

data1data2data3data4

What am I doing wrong???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 25th, 2005, 15:18
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
data1
?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 25th, 2005, 16:24
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP and textareas

Quote:
Originally Posted by ktsirig
What I want to do is when the user supplies ,for example, 4 data separated by <ENTER>, the page break not to dissapear, that is, I want

data1
data2
data3
data4

to remain as above and not

data1data2data3data4

What am I doing wrong???
You're doing nothing wrong - just that the new line character when included in an output stream of HTML just gives a white space.

Echo your ouput using:
nl2br(htmlspecialchars(stripslashes($_REQUEST[fred])))

where "fred" is the name of your textarea.

This solutions also protects you against users who echo HTML tags within your text area; in detail

stripslashes removes any extra \ characters added by PHP
htmlspecialchars encodes characters such as < & and "
nl2br changes any new line characters into
tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 25th, 2005, 22:41
Up'n'Coming Member
Join Date: Sep 2005
Location: athens
Age: 26
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
I guess I wasn't very clear in the first place.
Tha data which the user will write in the text area, are not shown to the screen via a PHP script. Instead, they are used as input for another PHP program doing other job. So, my problem is that I need to 'hold' the newline characters that may be inserted by the user when he/she presses the 'ENTER' key.
For example, if user writes:

My name is
Nick

the PHP program called through the textarea must treat the above lines as they are and not like

My name is Nick

That is my problem: What must I do to preserve the newline characters.

I think grahame's proposal is what I need.
Will try that!
Thanx to both of you for your time!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
php, textareas

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
selections within textareas benbacardi JavaScript Forum 16 Feb 16th, 2005 13:59


All times are GMT. The time now is 06:04.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42