Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Probleme php html with quote '
Hi
I try to read a variable $TITLE in e input firl type texte.
<TR><TD WIDTH='100'> Name:</TD>
<TD><input type='text'
name='titre'
size='60'
maxlength='60'
value='$TITRE'>
</TD><TR>";
The probleme is when I have a quote in the title like
mister O'Neil the field give only mister O. The quote has probleme with the
html quote.
how can I go around this problem
regards
claude



Report this thread to moderator Post Follow-up to this message
Old Post
Claude
04-02-08 01:12 PM


Re: Probleme php html with quote '
Claude a écrit :
> Hi
> I try to read a variable $TITLE in e input firl type texte.
> <TR><TD WIDTH='100'> Name:</TD>
> <TD><input type='text'
>       name='titre'
>       size='60'
>       maxlength='60'
>       value='$TITRE'>
>       </TD><TR>";
> The probleme is when I have a quote in the title like
> mister O'Neil the field give only mister O. The quote has probleme with th
e
> html quote.
> how can I go around this problem
> regards
> claude

You should use double quote for every attribute in HTML.
<input type="text" name="titre" size="60" maxlength="60" value="<?php
echo $TITRE; ?>" />

regarding special chars, an option is to use addslashes function. Or
just a str_replace('"', '\"', $TITRE) to handle the double quotes, same
could go for newlines, etc.

Regards,
--
Guillaume

Report this thread to moderator Post Follow-up to this message
Old Post
Guillaume
04-02-08 01:12 PM


Re: Probleme php html with quote '
Guillaume wrote:
> Claude a écrit : 
>
> You should use double quote for every attribute in HTML.
> <input type="text" name="titre" size="60" maxlength="60" value="<?php
> echo $TITRE; ?>" />
>
> regarding special chars, an option is to use addslashes function. Or
> just a str_replace('"', '\"', $TITRE) to handle the double quotes, same
> could go for newlines, etc.
>
> Regards,

The correct function to use here would be htmlspecialchars() (or
htmlentities()).

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


Report this thread to moderator Post Follow-up to this message
Old Post
Jerry Stuckle
04-02-08 01:12 PM


Re: Probleme php html with quote '
On 2 Apr, 13:08, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Guillaume wrote: 
> 
=3D"<?php 
> 
> 
>
> The correct function to use here would be htmlspecialchars() (or
> htmlentities()).
>

Jerry is right: html allows single quotes to be embedded within double
quotes and viceversa - but obviously this does not account for every
scenario.

Watch out for what you get back - there are various irreversible
versions of the magic quotes option. Going forward they are all
deperecated.

C.

Report this thread to moderator Post Follow-up to this message
Old Post
C. (http://symcbean.blogspot.com/)
04-02-08 01:12 PM


Re: Probleme php html with quote '
Jerry solution works well but I will try guillaume one to

thank very much
claude
"Jerry Stuckle" <jstucklex@attglobal.net> a écrit dans le message de news:
 sNadnTUPIJqs9G7anZ2dnUVZ_sHinZ2d@comcast
.com...
> Guillaume wrote: 
>
> The correct function to use here would be htmlspecialchars() (or
> htmlentities()).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
>



Report this thread to moderator Post Follow-up to this message
Old Post
Claude
04-02-08 01:12 PM


Re: Probleme php html with quote '
Claude schreef:
> Jerry solution works well but I will try guillaume one to
>
> thank very much
> claude

Hi Claude,

Are you going to use them both?
How?

Just use htmlspecialchars(), it is designed for excactly your problem.

Erwin Moller

> "Jerry Stuckle" <jstucklex@attglobal.net> a écrit dans le message de news:
>  sNadnTUPIJqs9G7anZ2dnUVZ_sHinZ2d@comcast
.com... 
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Erwin Moller
04-02-08 01:12 PM


Re: Probleme php html with quote '
Erwin Moller a écrit :
> Claude schreef: 
>
> Hi Claude,
>
> Are you going to use them both?
> How?
>
> Just use htmlspecialchars(), it is designed for excactly your problem.

Well mine was lazy, since my main point actually was to use double quote
on HTML attributes.
Still using str_replace *can* be added in case the input might have
newlines, which htmlspecialchars won't replace. But that is only for
very special cases, it should usually not be useful in any way.

Still, Jerry had the good point :p

Regards,
--
Guillaume

Report this thread to moderator Post Follow-up to this message
Old Post
Guillaume
04-02-08 01:12 PM


Re: Probleme php html with quote '
Guillaume wrote:
> Erwin Moller a écrit : 
>
> Well mine was lazy, since my main point actually was to use double quote
> on HTML attributes.
> Still using str_replace *can* be added in case the input might have
> newlines, which htmlspecialchars won't replace. But that is only for
> very special cases, it should usually not be useful in any way.
>
> Still, Jerry had the good point :p
>
> Regards,

For newline characters there is nl2br().

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


Report this thread to moderator Post Follow-up to this message
Old Post
Jerry Stuckle
04-03-08 12:20 AM


Re: Probleme php html with quote '
Jerry Stuckle a écrit :
> For newline characters there is nl2br().
Yep, but you might want something else (or nothing) than a "<br />" ^^

Regards,
--
Guillaume

Report this thread to moderator Post Follow-up to this message
Old Post
Guillaume
04-03-08 12:20 AM


Re: Probleme php html with quote '
..oO(Guillaume)

>Claude a écrit : 
>
>You should use double quote for every attribute in HTML.

Single quotes are perfectly fine. And even with double quotes you have
to escape some characters or you will have the same problem again.

Micha

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Fesser
04-03-08 12:20 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

PHP Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:26 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.