Best to use single or double quote for forming strings?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MrBiggles

    Best to use single or double quote for forming strings?

    Here's something I've been wondering. Do most of you use single or
    double quotes as a string encapsultor?

    ex:
    $s = "This is a string, I can embed ' with no prob";
    vs.
    $s = 'This is a string, I can embed " with no prob';

    Is there an advantage or best-practice reason to choose one over the other?

    Thanks!
  • Janwillem Borleffs

    #2
    Re: Best to use single or double quote for forming strings?

    MrBiggles wrote:[color=blue]
    > Here's something I've been wondering. Do most of you use single or
    > double quotes as a string encapsultor?
    >[/color]

    Depends if there are variables which should be parsed:

    $name = 'Joe';
    $str = "His name is $name";

    $str = 'His name is Joe';

    Double-quoted strings are parsed, while single-quoted strings are taken
    literally (= faster).


    JW


    Comment

    • Jasen Betts

      #3
      Re: Best to use single or double quote for forming strings?

      On 2006-02-18, MrBiggles <mrbiggles909@y ahoo.com> wrote:[color=blue]
      > Here's something I've been wondering. Do most of you use single or
      > double quotes as a string encapsultor?
      >
      > ex:
      > $s = "This is a string, I can embed ' with no prob";
      > vs.
      > $s = 'This is a string, I can embed " with no prob';
      >
      > Is there an advantage or best-practice reason to choose one over the other?[/color]

      the PHP manual chapter 11:

      download or otherwise get a copy of the PHP manual onto your LAN. it's much
      easier to use when you don't have to wait for it to come from a distant
      server

      Bye.
      Jasen

      Comment

      Working...