Double vs single quote

Discussion in 'HTML' started by Joshua Beall, Apr 21, 2004.

  1. Joshua Beall

    Joshua Beall Guest

    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
    Joshua Beall, Apr 21, 2004
    #1
    1. Advertising

  2. Joshua Beall

    C A Upsdell Guest

    "Joshua Beall" <> wrote in message
    news:ymxhc.29694$...
    > 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.
    C A Upsdell, Apr 21, 2004
    #2
    1. Advertising

  3. Joshua Beall

    Joshua Beall Guest

    "C A Upsdell" <cupsdell0311XXX@-@> 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.
    Joshua Beall, Apr 21, 2004
    #3
  4. Joshua Beall

    Jay Guest

    "Joshua Beall" <> wrote in message
    news:ymxhc.29694$...
    > 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
    Jay, Apr 21, 2004
    #4
  5. Joshua Beall

    Anthony Boyd Guest

    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.
    Anthony Boyd, Apr 22, 2004
    #5
  6. Joshua Beall

    Jeff Thies Guest

    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
    Jeff Thies, Apr 22, 2004
    #6
  7. 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
    Toby A Inkster, Apr 23, 2004
    #7
  8. Joshua Beall

    Joshua Beall Guest

    "Toby A Inkster" <> wrote in message
    news:p...
    > 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
    Joshua Beall, Apr 23, 2004
    #8
  9. Joshua Beall

    Phil Roberts Guest

    With total disregard for any kind of safety measures Toby A
    Inkster <> 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/
    Phil Roberts, Apr 24, 2004
    #9
  10. On Sat, 24 Apr 2004 09:01:32 -0500, Phil Roberts wrote:

    > With total disregard for any kind of safety measures Toby A
    > Inkster <> 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
    Toby A Inkster, Apr 24, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    13,191
  2. Eric Layman
    Replies:
    3
    Views:
    624
    Rad [Visual C# MVP]
    Apr 14, 2007
  3. Evan
    Replies:
    1
    Views:
    388
    Marc 'BlackJack' Rintsch
    Nov 4, 2008
  4. Evan
    Replies:
    3
    Views:
    516
    Marc 'BlackJack' Rintsch
    Nov 4, 2008
  5. vikrant
    Replies:
    8
    Views:
    359
    vikrant
    May 17, 2007
Loading...

Share This Page