Web Analytics Made Easy -
StatCounter Default Timezone Difference - CodingForum

Announcement

Collapse
No announcement yet.

Default Timezone Difference

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Default Timezone Difference

    I am confused between many php sources...

    Some wrote it:
    PHP Code:
    date_default_timezone_set('Europe/Paris'); 
    And others wrote it:
    PHP Code:
    date_default_timezone_set("Europe/Paris"); 
    The difference between the two is that the first Europe/Paris is between ' ' and the second is between " ".

    So what is the difference? And what is the correct way?

  • #2
    The difference is the PHP resources you use.

    Double quotes " mean that PHP will inspect the string and look for variables that it must replace with their values. If the string has no variables then there is no point using double quotes as you are wasting PHP resource cycles.

    Single quotes tell PHP that the string has no magic content inside and that it should be treated as-is.

    I have a link in my signature about quotes which goes into better detail if you need further clarification.

    In your scenario, you're not using $Location so you can just use 'Europe/Paris'
    "Tango says double quotes with a single ( ' ) quote in the middle"
    '$Name says single quotes with a double ( " ) quote in the middle'
    "Tango says double quotes ( \" ) must escape a double quote"
    '$Name single quotes ( \' ) must escape a single quote'

    Comment


    • #3
      Originally posted by Tony M View Post
      I am confused between many php sources...

      Some wrote it:
      PHP Code:
      date_default_timezone_set('Europe/Paris'); 
      And others wrote it:
      PHP Code:
      date_default_timezone_set("Europe/Paris"); 
      The difference between the two is that the first Europe/Paris is between ' ' and the second is between " ".

      So what is the difference? And what is the correct way?
      PHP uses the two quotation marks for different things. Double quotes will force php to look for a variable inside the enclosure whereas single quotes will tell PHP there are no variables inside the enclosure - treat as a pure string. In your case, ' is your prefered choice

      Edit: Dammit tangoforce you beat me too it lol!
      Last edited by BluePanther; Aug 18, 2011, 08:34 PM. Reason: Tangoforce beat me to it!
      Useful function to retrieve difference in times
      The best PHP resource
      A good PHP FAQ
      PLEASE remember to wrap your code in [PHP] tags.
      PHP Code:
      // Replace this
      if(isset($_POST['submitButton']))
      // With this
      if(!empty($_POST))
      // Then check for values/forms. Some IE versions don't send the submit button 
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

      Comment


      • #4
        Type faster
        "Tango says double quotes with a single ( ' ) quote in the middle"
        '$Name says single quotes with a double ( " ) quote in the middle'
        "Tango says double quotes ( \" ) must escape a double quote"
        '$Name single quotes ( \' ) must escape a single quote'

        Comment

        Working...
        X