SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,784
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Single and Double Quotes

    In my HTML, does it matter which of these formats I use...

    Option #1:
    HTML Code:
    	<ul id="topMenu">

    Option #2:
    HTML Code:
    	<ul id='topMenu'>

    When I write PHP, I tend to use this format in my echo statements...
    PHP Code:
    echo     "<ul id='topMenu'>"
    ...because it allows PHP to recognize embedded variables.

    So for consistency, I guess I would prefer to use Option #2 when I have straight-HTML.

    Does it really matter?

    Sincerely,


    Debbie

  2. #2
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,806
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    no. It functionally doesnt matter whether you enclose attributes in quotes or double quotes. Tho I can see how double quotes would go with the double D brand.. (or did I get that backwards) lol


    One PHP tip:

    Code:
    echo     '<ul id="topMenu">';  
    
    echo     '<ul id="', $id , '">';
    is marginally faster than

    Code:
    echo     "<ul id='topMenu'>";  
    
    echo     "<ul id='$id'>";

  3. #3
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,268
    Mentioned
    116 Post(s)
    Tagged
    1 Thread(s)
    According to the spec, it doesn't matter. So it comes down to personal preference.

    I personal prefer the double quotes, but I can understand why you'd want to do it your way (though there are other ways to accomplish the same thing)

    Edit:

    bah! Dres beat me
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  4. #4
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,784
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dresden_phoenix View Post
    no. It functionally doesnt matter whether you enclose attributes in quotes or double quotes.
    Glad to hear I have options!


    Quote Originally Posted by dresden_phoenix View Post
    Tho I can see how double quotes would go with the double D brand.. (or did I get that backwards) lol
    Ha ha!


    Quote Originally Posted by dresden_phoenix View Post
    One PHP tip:

    Code:
    echo     '<ul id="topMenu">';  
    
    echo     '<ul id="', $id , '">';
    is marginally faster than

    Code:
    echo     "<ul id='topMenu'>";  
    
    echo     "<ul id='$id'>";
    That is because things in single quotes in PHP are taken as literals and thus don't need to be interpreted, right?

    Sincerely,


    Debbie

  5. #5
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    When echoing HTML, I almost exclusively do it like this:

    Code:
    $linktext='Visit example.org today!';
    echo '<a href="http://example.org">'.$linktext.'</a>';
    This is to avoid having to escape characters, as that tends to get messy and introduces errors.
    Last edited by Force Flow; Oct 3, 2013 at 18:27. Reason: typo
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  6. #6
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,280
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    whut-evah yew wa-ont, so long's you's consistent

    '"'"'"

  7. #7
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,784
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    whut-evah yew wa-ont, so long's you's consistent

    '"'"'"
    Apparently a little *too much* wine...


    Debbie


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •