469,592 Members | 2,063 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

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 2044
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Chamomile | last post: by
7 posts views Thread by daniel kaplan | last post: by
1 post views Thread by Gernot Frisch | last post: by
7 posts views Thread by Fabien LE LEZ | last post: by
7 posts views Thread by =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.