www.webdeveloper.com
Results 1 to 3 of 3

Thread: Single quotes VS double quotes

  1. #1
    Join Date
    May 2009
    Posts
    14

    Single quotes VS double quotes

    Is there a difference between PHP's treatment of single quotes and that of double quotes?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,154
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2009
    Posts
    2
    single quote:
    To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash before a single quote, or at the end of the string, double it (\\). Note that attempting to escape any other character will print the backslash too.

    for e.g.

    <?php
    echo 'this is a simple string';

    echo 'You can also have embedded newlines in
    strings this way as it is
    okay to do';

    // Outputs: Arnold once said: "I'll be back"
    echo 'Arnold once said: "I\'ll be back"';

    // Outputs: You deleted C:\*.*?
    echo 'You deleted C:\\*.*?';

    // Outputs: You deleted C:\*.*?
    echo 'You deleted C:\*.*?';

    // Outputs: This will not expand: \n a newline
    echo 'This will not expand: \n a newline';

    // Outputs: Variables do not $expand $either
    echo 'Variables do not $expand $either';
    ?>

    double Quote:
    As in single quoted strings, escaping any other character will result in the backslash being printed too. Before PHP 5.1.1, the backslash in \{$var} had not been printed.

    The most important feature of double-quoted strings is the fact that variable names will be expanded. See string parsing for details.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles