Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   HTML (http://www.velocityreviews.com/forums/f31-html.html)
-   -   Double vs single quote (http://www.velocityreviews.com/forums/t157752-double-vs-single-quote.html)

Joshua Beall 04-21-2004 04:32 PM

Double vs single quote
 
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



C A Upsdell 04-21-2004 04:37 PM

Re: Double vs single quote
 
"Joshua Beall" <jbeall@donotspam.remove.me.heraldic.us> wrote in message
news:ymxhc.29694$G_.10376@nwrddc02.gnilink.net...
> 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.




Joshua Beall 04-21-2004 04:44 PM

Re: Double vs single quote
 
"C A Upsdell" <cupsdell0311XXX@-@-@XXXrogers.com> 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.



Jay 04-21-2004 06:39 PM

Re: Double vs single quote
 
"Joshua Beall" <jbeall@donotspam.remove.me.heraldic.us> wrote in message
news:ymxhc.29694$G_.10376@nwrddc02.gnilink.net...
> 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



Anthony Boyd 04-22-2004 07:45 AM

Re: Double vs single quote
 
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.


Jeff Thies 04-22-2004 06:48 PM

Re: Double vs single quote
 
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



Toby A Inkster 04-22-2004 11:14 PM

Re: Double vs single quote
 
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


Joshua Beall 04-23-2004 01:27 PM

Re: Double vs single quote
 
"Toby A Inkster" <UseTheAddressInMySig@deadspam.com> wrote in message
news:pan.2004.04.22.23.14.07.541806@goddamn.co.uk. ..
> 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



Phil Roberts 04-24-2004 02:01 PM

Re: Double vs single quote
 
With total disregard for any kind of safety measures Toby A
Inkster <UseTheAddressInMySig@deadspam.com> 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/

Toby A Inkster 04-24-2004 08:50 PM

Re: Double vs single quote
 
On Sat, 24 Apr 2004 09:01:32 -0500, Phil Roberts wrote:

> With total disregard for any kind of safety measures Toby A
> Inkster <UseTheAddressInMySig@deadspam.com> 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



All times are GMT. The time now is 06:10 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.