Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For HTML and Javascript it's down to preference, but PHP is different.</p> <p>In HTML, tag attributes can be either double or single quotes - this is defined in <a href="http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes" rel="nofollow">the spec</a>. If you check page sources, most people seem to use double quotes, but there is nothing to stop you using single quotes.</p> <p>In Javascript there is no reason to use one more than the other - indeed, usage seems to be pretty split. One consideration that you've noted, is that if you're double quoting your HTML attributes, then single quoting your Javascript strings means you can use inline Javascript without breaking your normal style. E.g. <code>&lt;a href="alert('Hello, world')"&gt;</code>. A good introduction is available <a href="http://www.quirksmode.org/js/strings.html" rel="nofollow">here</a>.</p> <p>PHP is different however. Double quoted strings are parsed for variables, requiring additional overhead. It's not going to be a massive drain, but it's certainly good practice. In PHP</p> <pre><code>$string = 'This is my ' . $variable; </code></pre> <p>and</p> <pre><code>$string = "This is my $variable"; </code></pre> <p>produce equivalent output. For that reason, it is more efficient to use single quoted strings in PHP, or learn to use double <a href="http://php.net/manual/en/language.types.string.php" rel="nofollow">quoted string syntax</a> when necessary.</p> <p>In the end, it's entirely up to you, but these are the norms. You won't be penalised if you stray from standard usage, but it's important to understand the full implications, especially with PHP.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload