Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Double vs single quote

Reply
Thread Tools

Double vs single quote

 
 
Joshua Beall
Guest
Posts: n/a
 
      04-21-2004
Hi All,

The W3C validator does not seem to mind single-quoted attributes, but I have
heard it said that using single quotes to delimit attribute values can get
you into trouble with some browsers. Is that still a real problem today?
What are some thoughts on this?

-Josh


 
Reply With Quote
 
 
 
 
C A Upsdell
Guest
Posts: n/a
 
      04-21-2004
"Joshua Beall" <(E-Mail Removed)> wrote in message
news:ymxhc.29694$(E-Mail Removed)...
> Hi All,
>
> The W3C validator does not seem to mind single-quoted attributes, but I

have
> heard it said that using single quotes to delimit attribute values can get
> you into trouble with some browsers. Is that still a real problem today?
> What are some thoughts on this?


If a browser has a problem with single quotes, it is defective. I have
never myself encountered such a problem.



 
Reply With Quote
 
 
 
 
Joshua Beall
Guest
Posts: n/a
 
      04-21-2004
"C A Upsdell" <cupsdell0311XXX@-@(E-Mail Removed)> wrote in message
news:7rxhc.10809
> If a browser has a problem with single quotes, it is defective. I have
> never myself encountered such a problem.


Yeah, I realize that - what I am asking is, are there many browsers out
there like this? I have never encountered one myself either.


 
Reply With Quote
 
Jay
Guest
Posts: n/a
 
      04-21-2004
"Joshua Beall" <(E-Mail Removed)> wrote in message
news:ymxhc.29694$(E-Mail Removed)...
> Hi All,
>
> The W3C validator does not seem to mind single-quoted attributes, but I

have
> heard it said that using single quotes to delimit attribute values can get
> you into trouble with some browsers. Is that still a real problem today?
> What are some thoughts on this?


My ASP pages write HTML tags with single quoted attributes and I've never
seen any browser have a problem with them.

<% response.write "<p id='mainP'>Text</p>" %>


--
"Some see the glass as half-empty;
some see the glass as half-full.
I see the glass as too big." - George Carlin

- J


 
Reply With Quote
 
Anthony Boyd
Guest
Posts: n/a
 
      04-22-2004
Jay wrote:
>
> My ASP pages write HTML tags with single quoted attributes and I've never
> seen any browser have a problem with them.
>
> <% response.write "<p id='mainP'>Text</p>" %>


Yes, I always used single quotes in HTML for the same reason. However,
(and this is unverified second-hand stuff), PHP offers some functions to
escape strings, but they don't escape single quotes. Off the top of my
head, I think it was htmlspecialchars. So this wouldn't work:

$name = "Jon's Coffee Store";
$name = htmlspecialchars($name);
print "<input type='text' name='foo' value='$name' />";

Because it ends up looking like this:

<input type='text' name='foo' value='Jon's Coffee Store' />

In other words, only "Jon" appears as the value. So the people I work
with have decided to use normal quotes for HTML, and single quotes for
their print statements. Supposedly it's faster than interpolated
strings anyway. Like this:

echo '<input type="text" name="foo" value="', $name, '" />';

FWIW.

 
Reply With Quote
 
Jeff Thies
Guest
Posts: n/a
 
      04-22-2004
A bit offtopic question about PHP. I seldom use it... Nothing against it.

> Yes, I always used single quotes in HTML for the same reason. However,
> (and this is unverified second-hand stuff), PHP offers some functions to
> escape strings, but they don't escape single quotes. Off the top of my
> head, I think it was htmlspecialchars. So this wouldn't work:
>
> $name = "Jon's Coffee Store";
> $name = htmlspecialchars($name);
> print "<input type='text' name='foo' value='$name' />";


Doesn't PHP offer other methods of defining strings?

For example in Perl:

print qq{<input type="text" name="foo" value="$name" />
variables are interpolated, a single q is non interpolated

};

or a heredoc

print <<thishtml;
<input type="text" name="foo" value="$name" />
variables are interpolated, print <<'thishtml' is non interpolated

thishtml

as well as this:

print '<input type="text" name="foo" value=" ' . $name . ' " />';

or this:

print "<input type=\"text\" name=\"foo\" value=\"$name\" />";

or (escaping done automatically, value can have single or double quotes) :

use CGI;
my $q=new CGI;
print $q->textfield(-name=>'foo',-value=>$bar);

There's others also...

I know ASP lacks these, but I just sort of assumed this was doable in PHP.

Jeff


 
Reply With Quote
 
Toby A Inkster
Guest
Posts: n/a
 
      04-22-2004
Jeff Thies wrote:

> Doesn't PHP offer other methods of defining strings?


PHP ain't as flexible with strings as Perl is. It has '...', "..." and
`...` (which all work the same way as in Perl) and that's about it.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?page=132

 
Reply With Quote
 
Joshua Beall
Guest
Posts: n/a
 
      04-23-2004
"Toby A Inkster" <(E-Mail Removed)> wrote in message
news(E-Mail Removed). ..
> Jeff Thies wrote:
>
> > Doesn't PHP offer other methods of defining strings?

>
> PHP ain't as flexible with strings as Perl is. It has '...', "..." and
> `...` (which all work the same way as in Perl) and that's about it.


Actually it has another way of doing it: the heredoc syntax. Looks like
this:

$name = 'Josh';
$HTML = <<<EOT
<p class="pTitle">The heredoc syntax</p>

<p class='text'> The heredoc syntax allows you to use single and double
quotes, without escaping either. Additionally, you can embed variables,
like
my name, $name. If you want to embed complex variables (e.g., arrays,
properties of objects), you want to put curly brackets around the variable,
like this: {$_SERVER['HTTP_USER_AGENT']}.</p>

<p>Additioanlly, tyings like \n, \r, \t, etc., will all be interpreted as
expected,
not literally placed in the string.</p>

<p>Great, ain't it?</p>
EOT;

echo $HTML; // Send it to the browser

I use the heredoc syntax all the time; it's great. There is also nothing
stopping you from echoing the string to the screen immediately, as opposed
to first storing it in a variable, and then echoing it to the screen.

-Josh


 
Reply With Quote
 
Phil Roberts
Guest
Posts: n/a
 
      04-24-2004
With total disregard for any kind of safety measures Toby A
Inkster <(E-Mail Removed)> leapt forth and
uttered:

> Jeff Thies wrote:
>
>> Doesn't PHP offer other methods of defining strings?

>
> PHP ain't as flexible with strings as Perl is. It has '...',
> "..." and `...` (which all work the same way as in Perl) and
> that's about it.
>


If you delimit a string with `` PHP will attempt to execute it as a
system command.

--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/
 
Reply With Quote
 
Toby A Inkster
Guest
Posts: n/a
 
      04-24-2004
On Sat, 24 Apr 2004 09:01:32 -0500, Phil Roberts wrote:

> With total disregard for any kind of safety measures Toby A
> Inkster <(E-Mail Removed)> leapt forth and
> uttered:
>
>> PHP ain't as flexible with strings as Perl is. It has '...',
>> "..." and `...` (which all work the same way as in Perl) and
>> that's about it.

>
> If you delimit a string with `` PHP will attempt to execute it as a
> system command.


Aha. Just like in Perl.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?page=132

 
Reply With Quote
 
 
 
Reply

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with single-quote and double-quote when using subprocess. Evan Python 3 11-04-2008 12:24 PM
problem with quote and single-quote when using "subprocess" Evan Python 1 11-04-2008 12:08 AM
How to handling string contains single quote and double quote vikrant Perl Misc 8 05-17-2007 04:37 PM
Datagrid on load; replace all double single quote to single quote to display to user Eric Layman ASP .Net 3 04-14-2007 07:16 AM
Single Quote Versus Double Quote In A href link knee-dragger@hotmail.com HTML 3 06-13-2006 12:42 AM



Advertisments