473,409 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Textarea handling in php ?

I'm learning a little about using forms in php to enter data, and have a
couple of questions re textarea.
At the moment I just use "addslashes() to process the value from textarea so
that punctuation is escaped, and write this into a table.
When the text wraps in the text box I get a new line in the value returned,
as well as new lines that I enter manually.
Is it possible to remove the wrap new line but keep the user entered new
line ?

Mar 18 '08 #1
20 2207
Tony B wrote:
I'm learning a little about using forms in php to enter data, and have a
couple of questions re textarea.
At the moment I just use "addslashes() to process the value from textarea so
that punctuation is escaped, and write this into a table.
When the text wraps in the text box I get a new line in the value returned,
as well as new lines that I enter manually.
Is it possible to remove the wrap new line but keep the user entered new
line ?

First of all, you shouldn't be using addslashes(). If you're writing to
a MySQL database, you should be using mysql_real_escape_string() instead.

As for the new lines - how is your code to know which are inserted by
the textarea and which are inserted by the user? Better to use send the
data correctly in the first place. See the WRAP attribute of a textarea .

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 18 '08 #2
On 18 Mar, 12:18, Jerry Stuckle <jstuck...@attglobal.netwrote:
Tony B wrote:
I'm learning a little about using forms in php to enter data, and have a
As for the new lines - how is your code to know which are inserted by
the textarea and which are inserted by the user? Better to use send the
data correctly in the first place. See the WRAP attribute of a textarea .

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Surely that should have been: "Better to use send the data correctly
in the first place. See the WRAP attribute of a textarea. But this
has nothing to do with php.

;-)
Mar 18 '08 #3
Captain Paralytic wrote:
On 18 Mar, 12:18, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Tony B wrote:
>>I'm learning a little about using forms in php to enter data, and have a
As for the new lines - how is your code to know which are inserted by
the textarea and which are inserted by the user? Better to use send the
data correctly in the first place. See the WRAP attribute of a textarea .

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Surely that should have been: "Better to use send the data correctly
in the first place. See the WRAP attribute of a textarea. But this
has nothing to do with php.

;-)
True. :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 18 '08 #4

"Tony B" <ta****@yahoo.co.ukwrote in message
news:ae******************@fe05.news.easynews.com.. .
I'm learning a little about using forms in php to enter data, and have a
couple of questions re textarea.
At the moment I just use "addslashes() to process the value from textarea
so that punctuation is escaped, and write this into a table.
When the text wraps in the text box I get a new line in the value
returned, as well as new lines that I enter manually.
Is it possible to remove the wrap new line but keep the user entered new
line ?

IIRD, "wrap" is not an attribute of textarea in any version of html or xhtml
I've used - it's a proprietary attribute of Netscape/IE. You're just asking
for cross-browser trouble if you use it. Check out the white-space attribute
of CSS.

If this is for web display and you need to generate a hard new line in html,
use <br />.

Mar 18 '08 #5
First of all, you shouldn't be using addslashes(). If you're writing to a
MySQL database, you should be using mysql_real_escape_string() instead.

As for the new lines - how is your code to know which are inserted by the
textarea and which are inserted by the user? Better to use send the data
correctly in the first place. See the WRAP attribute of a textarea .

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Thanks for the pointer. I wasn't worried about sql injection as these are
not on public pages, but worth knowing for the future.
The wrap attribute does what I need.
Thanks
Tony
Mar 18 '08 #6
Tony B wrote:
>First of all, you shouldn't be using addslashes(). If you're writing to a
MySQL database, you should be using mysql_real_escape_string() instead.

As for the new lines - how is your code to know which are inserted by the
textarea and which are inserted by the user? Better to use send the data
correctly in the first place. See the WRAP attribute of a textarea .

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Thanks for the pointer. I wasn't worried about sql injection as these are
not on public pages, but worth knowing for the future.
The wrap attribute does what I need.
Thanks
Tony
You need to be worried about SQL injection, especially on internal
sites. More damage can be done by disgruntled employees than hackers.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 18 '08 #7

"Mason Barge" <ma********@comcast.netwrote in message
news:V6******************************@comcast.com. ..
>
"Tony B" <ta****@yahoo.co.ukwrote in message
news:ae******************@fe05.news.easynews.com.. .
>I'm learning a little about using forms in php to enter data, and have a
couple of questions re textarea.
At the moment I just use "addslashes() to process the value from textarea
so that punctuation is escaped, and write this into a table.
When the text wraps in the text box I get a new line in the value
returned, as well as new lines that I enter manually.
Is it possible to remove the wrap new line but keep the user entered new
line ?


IIRD, "wrap" is not an attribute of textarea in any version of html or
xhtml I've used - it's a proprietary attribute of Netscape/IE. You're
just asking for cross-browser trouble if you use it. Check out the
white-space attribute of CSS.

If this is for web display and you need to generate a hard new line in
html, use <br />.
What I want is textarea not to insert line breaks just because the user
enters a line that is longer than the number of columns. Wrap can do this in
IE/FF/Opera etc.
I cannot see how css can alter the behaviour of textarea as to whether it
inserts hard line breaks when a line wraps in the textarea box ?
Mar 19 '08 #8
On 19 Mar, 09:31, "Tony B" <to...@imageproc.comwrote:
I cannot see how css can alter the behaviour of textarea as to whether it
inserts hard line breaks when a line wraps in the textarea box ?
Cannot see or haven't tried to?
I put
css white-space
into Gogle and pressed "I'm Feeling Lucky" and got a pretty good
explanation.
Mar 19 '08 #9
On 19 Mar, 09:57, Captain Paralytic <paul_laut...@yahoo.comwrote:
On 19 Mar, 09:31, "Tony B" <to...@imageproc.comwrote:I cannot see how css can alter the behaviour of textarea as to whether it
inserts hard line breaks when a line wraps in the textarea box ?

Cannot see or haven't tried to?
I put
css white-space
into Gogle and pressed "I'm Feeling Lucky" and got a pretty good
explanation.
And this explains even better:
http://www.w3.org/TR/CSS21/text.html#white-space-prop
Mar 19 '08 #10
Captain Paralytic wrote:
On 19 Mar, 09:31, "Tony B" <to...@imageproc.comwrote:
>I cannot see how css can alter the behaviour of textarea as to whether it
inserts hard line breaks when a line wraps in the textarea box ?
Cannot see or haven't tried to?
I put
css white-space
into Gogle and pressed "I'm Feeling Lucky" and got a pretty good
explanation.
That doesn't stop the insertion of a line break when the text wraps. It
just controls whether the line wraps or not.

No, "wrap" is not an HTML attribute, but it is supported every recent
browser I've tried.

And for Tony, <br /is not a valid html break.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 19 '08 #11
Captain Paralytic wrote:
On 19 Mar, 09:57, Captain Paralytic <paul_laut...@yahoo.comwrote:
>On 19 Mar, 09:31, "Tony B" <to...@imageproc.comwrote:I cannot see how css can alter the behaviour of textarea as to whether it
>>inserts hard line breaks when a line wraps in the textarea box ?
Cannot see or haven't tried to?
I put
css white-space
into Gogle and pressed "I'm Feeling Lucky" and got a pretty good
explanation.

And this explains even better:
http://www.w3.org/TR/CSS21/text.html#white-space-prop
Ah, yes - now I see...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 19 '08 #12
On 19 Mar, 12:01, Jerry Stuckle <jstuck...@attglobal.netwrote:
Captain Paralytic wrote:
On 19 Mar, 09:57, Captain Paralytic <paul_laut...@yahoo.comwrote:
On 19 Mar, 09:31, "Tony B" <to...@imageproc.comwrote:I cannot see how css can alter the behaviour of textarea as to whether it
inserts hard line breaks when a line wraps in the textarea box ?
Cannot see or haven't tried to?
I put
css white-space
into Gogle and pressed "I'm Feeling Lucky" and got a pretty good
explanation.
And this explains even better:
http://www.w3.org/TR/CSS21/text.html#white-space-prop

Ah, yes - now I see...
Yes, as has been metioned in recent threads, w3schools is good for an
introduction, but it doesn't always tell one the whole truth.
I do think that this particular w3.org section is one of their clearer
ones.
Mar 19 '08 #13
Jerry Stuckle wrote:
And for Tony, <br /is not a valid html break.
"<br/>" is valid in HTML. It just doesn't mean what people think it means.
It is equivalent to "<br>&gt;" because of SGML shorttag rules.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 13:37.]

The Semantic Web
http://tobyinkster.co.uk/blog/2008/03/09/sw/
Mar 19 '08 #14
Captain Paralytic wrote:
Yes, as has been metioned in recent threads, w3schools is good for an
introduction, but it doesn't always tell one the whole truth. I do think
that this particular w3.org section is one of their clearer ones.
w3.org and w3schools.com are entirely different websites. Do not get them
mixed up.

w3.org is the World Wide Web Consortium (W3C), an organisation set up by
Sir Tim Berners-Lee to steer the development of the web, supported by many
academic organisations, browser makers and content producers. They have
been responsible for all HTML specifications since version 3.2, and for
CSS, the DOM, XML, SVG, RDF, SOAP and various other web-related
technologies. This responsibility for them has been informally delegated
to them by the IETF.

w3schools.com is a tutorial website owned by a small Norwegian company
called Refsnes Data. Although their tutorials are generally fairly good,
the company is in no way affiliated with the W3C, and their tutorials are
no more "official" than any turoial you or I could put together. Most of
their tutorials are aimed at helping your learn W3C standards, and other
web-related technologies.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 13:56.]

The Semantic Web
http://tobyinkster.co.uk/blog/2008/03/09/sw/
Mar 19 '08 #15
On Wed, 19 Mar 2008 12:53:50 +0100, Toby A Inkster
<us**********@tobyinkster.co.ukwrote:
Jerry Stuckle wrote:
>And for Tony, <br /is not a valid html break.

"<br/>" is valid in HTML. It just doesn't mean what people think it
means.
It is equivalent to "<br>&gt;" because of SGML shorttag rules.
..... extending up to the next /.
('<br/>I don't know / don't care' == '<br>&gt;I don't know</brdon't care)

No mainstream UA interprets it like that to my knowledge, but mixing HTML
& XHTML is still a bad idea indeed.
--
Rik Wasmus
Mar 19 '08 #16
Toby A Inkster wrote:
Jerry Stuckle wrote:
>And for Tony, <br /is not a valid html break.

"<br/>" is valid in HTML. It just doesn't mean what people think it means.
It is equivalent to "<br>&gt;" because of SGML shorttag rules.
Actually, it's not valid. It's only valid in XHTML. Most browsers
accept it, but that doesn't mean it's legal.

In HTML 4.01. the end tag is forbidden. See
http://www.w3.org/TR/html401/struct/text.html#edef-BR
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 19 '08 #17
Rik Wasmus wrote:
Toby A Inkster wrote:
>>
"<br/>" is valid in HTML. It just doesn't mean what people think it
means. It is equivalent to "<br>&gt;" because of SGML shorttag rules.

.... extending up to the next /.
('<br/>I don't know / don't care' == '<br>&gt;I don't know</brdon't
care)
In the case of something like <b/>.../ or <p/>.../ you would be right, but
the HTML DTD explicitly declares the <brelement to be empty, so no
second slash is required to close the element.
No mainstream UA interprets it like that to my knowledge
Nope. And a good thing too -- otherwise the backwards compatibility of
XHTML wouldn't "work".

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 19:28.]

The Semantic Web
http://tobyinkster.co.uk/blog/2008/03/09/sw/
Mar 19 '08 #18
Jerry Stuckle wrote:
Toby A Inkster wrote:
>"<br/>" is valid in HTML. It just doesn't mean what people think it
means. It is equivalent to "<br>&gt;" because of SGML shorttag rules.

Actually, it's not valid.
Actually it is:
http://examples.tobyinkster.co.uk/br/br

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 19:28.]

The Semantic Web
http://tobyinkster.co.uk/blog/2008/03/09/sw/
Mar 19 '08 #19
Toby A Inkster wrote:
Jerry Stuckle wrote:
>Toby A Inkster wrote:
>>"<br/>" is valid in HTML. It just doesn't mean what people think it
means. It is equivalent to "<br>&gt;" because of SGML shorttag rules.
Actually, it's not valid.

Actually it is:
http://examples.tobyinkster.co.uk/br/br
See the rest of my message - and the link to the W3C spec which shows it
is NOT valid.

Just because the validator doesn't catch the error does not mean it's valid.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 19 '08 #20
..oO(Jerry Stuckle)
>Toby A Inkster wrote:
>Jerry Stuckle wrote:
>>Toby A Inkster wrote:

"<br/>" is valid in HTML. It just doesn't mean what people think it
means. It is equivalent to "<br>&gt;" because of SGML shorttag rules.
Actually, it's not valid.

Actually it is:
http://examples.tobyinkster.co.uk/br/br

See the rest of my message - and the link to the W3C spec which shows it
is NOT valid.
<br/means completely different things in HTML and XHTML. Following
SGML minimization rules the slash implicitly closes the start tag and
there's no end tag. The following is just character data.

http://www.cs.tut.fi/~jkorpela/html/empty.html#why

You could replace the with whatever you like: x<br/y is perfectly
valid HTML and should render as

x
y

but of course it won't in most browsers.
>Just because the validator doesn't catch the error does not mean it's valid.
The validator doesn't catch it because in this case it is not an error.

Micha
Mar 19 '08 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Phil Powell | last post by:
The customer made a wild request: they want on their admin panel a textarea that will display an existing resume. This textarea, however, must have a dynamic width, one that "fills the screen...
4
by: Chamomile | last post by:
does anyone know if its possible to full-justfy text in a <textarea>? I can do left and right justify and center with a simple style declaration, but can't find any reference anywhere to a full...
7
by: daniel kaplan | last post by:
hello all, am new to HTML and am in the process of creating a form, no serious headaches, but am stumped on two types of fields. i can take care of these situations using javascript, but was...
1
by: Gernot Frisch | last post by:
Hi, I want to be able to select 3 rows of a textarea, and when pressing "Tab/shift Tab" indent the source code edited. Can I do this with JavaScript? -- -Gernot int main(int argc, char**...
7
by: Fabien LE LEZ | last post by:
Hello, I'd like to put, on a web page, a "place" where the user can type a rather long text, with automatic coloring of each word (e.g. a color depending on the number of letters of the word). ...
3
by: zjw2112 | last post by:
Hello. I have some javascript code that dynamically creates a textarea and sets the wrap value to hard, which I thought would preserve CR/LF in the textarea: var otherTextArea =...
2
by: draven76 | last post by:
Hi, I've got an html form with a big textarea. It's max 90 lines, 58 chars per line (there is a script that, when you write the form, cuts off the 59th char and warns you not to go beyond 58 chars...
3
by: Jake Barnes | last post by:
I'm researching the Enter key. This is for an Ajax chat application. The designer tells me that she wants people to be able to submit text simply by hitting the Enter key. She wants this to happen...
7
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
I need to emulate the missing "maxlegth" attribute in "textarea" fields but all my Google searches either lead to obsolete scripts that overwrite the "value" property (thus losing caret position)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.