1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Rep Power

    Single Quote or Double quotes

    Okay I have found several examples going one way or the other as to which way is better and which way is better for several different needs. I thought I would just ask one more time for me and for all those wondering people in the world.
    Which way is more proper?

    Option A:
    PHP Code:
    echo "<td><input type=\"number\" size=\"18\" name=\"add_quantity_aEdit\"></td>"

    Option B:
    echo '<td><input type="number" size="18" name="add_quantity_aEdit"></td>';
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power

    isn't that obvious? Unless you really like backslashes, you should never use double quotes in a double-quoted string or single quotes in a single-quoted string.

    Either use different quotes. Or even better: Get rid of the PHPHTML mixture altogether and use a dedicated template engine like Twig. Nested languages are always an ugly matter. Your example is relatively harmless, but I've seen people nest JavaScript in HTML in PHP.

    If you wonder about the difference between single quotes and double quotes: Double-quoted strings get evaluated and can contain variables or special character sequences like \n (a newline). A single quoted string is a raw sequence of characters. It's generally safer to use single quotes, because you don't run into trouble if your string happens to contain a "$" or something.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo