1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Which Version Is Correct?

Discussion in 'PHP & Perl' started by The Scarlet Pimp, Aug 23, 2008.

  1. The Scarlet Pimp

    The Scarlet Pimp Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 2, 2008
    Messages:
    788
    Likes Received:
    3,120
    Occupation:
    Chair moistener.
    Location:
    Cyberspace
    these both work, but i'd like to know if one is correct...

    header("Location: http://www.domain.com");

    header('Location: http://www.domain.com');


    tsp
     
  2. bscan

    bscan Newbie

    Joined:
    Aug 17, 2008
    Messages:
    13
    Likes Received:
    0
    Both are correct.
    In most cases it's just a way you write code.
    But there are some small differences.
    See PHP manual for that:
    http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
     
  3. The Scarlet Pimp

    The Scarlet Pimp Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 2, 2008
    Messages:
    788
    Likes Received:
    3,120
    Occupation:
    Chair moistener.
    Location:
    Cyberspace
    good show! seems double quotes are to be used if you have string data,
    and single quotes are used for literal translation. wish i'd started learning
    php several years ago.

    thanx! :D

    tsp
     
  4. ContentFarmer

    ContentFarmer Junior Member

    Joined:
    Sep 21, 2007
    Messages:
    122
    Likes Received:
    12
    Occupation:
    Owner
    Location:
    Reno, NV
    Home Page:
    Use single quotes unless you have a bunch of single quotes in the string. PHP parses single quotes a bit faster b/c it doesn't have to search or replace variables in the string.
     
  5. barigain

    barigain Junior Member

    Joined:
    Aug 23, 2012
    Messages:
    100
    Likes Received:
    12
    A single-quoted string does not have variables within it interpreted. A double-quoted string does.
    Also, a double-quoted string can contain apostrophes without backslashes, while a single-quoted string can contain unescaped quotation marks.
    The single-quoted strings are faster at runtime because they do not need to be parsed.
     
    Last edited by a moderator: Dec 26, 2013