Thread: Quotes in PHP

Results 1 to 5 of 5
  1. #1 Quotes in PHP 
    ???

    funkE's Avatar
    Join Date
    Feb 2008
    Posts
    2,606
    Thanks given
    242
    Thanks received
    977
    Discord
    View profile
    Rep Power
    1281
    More of an informational post.. not really a tutorial.

    Hint: single quotes are faster but you need to concatenate variables

    Example:
    Code:
    $toAppend = 'dicks';
    echo('i like '.$toAppend);
    Output: i like dicks

    With double quotes you can do the above or just let PHP handle parsing it:
    Code:
    $toAppend = 'dicks';
    echo("i like ".$toAppend." and $toAppend");
    Output: i like dicks and dicks

    Tip: as far as I know you need double quotes to use string literals (\r, \n, \t, \s, etc.). if you want a new line you can always use the PHP_EOL constant (cross-platform, bros!!!)

    I don't really feel like elaborating on this subject but the difference is so minuscule, it doesn't even matter in most cases. It's a good habit to always use single quotes though. Double quotes when you absolutely need to or couldn't be fucked to optimize.
    .
    Reply With Quote  
     

  2. #2  
    Registered Member
    Ant-Man's Avatar
    Join Date
    Aug 2010
    Posts
    1,018
    Thanks given
    277
    Thanks received
    177
    Rep Power
    452
    This is what I like to call common sense.

    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Mar 2011
    Posts
    8
    Thanks given
    0
    Thanks received
    2
    Rep Power
    0
    No, this is wrong. You are on the right track/idea but you have no clue what you are talking about.

    -----

    Single quotes run a lot faster because the computer is not attempting to execute your code when it doesn't need to.

    Double quotes run slower because the computer is attempting to execute your code inside the quotes. Double quotes are similar to the eval PHP native function.
    Reply With Quote  
     

  4. #4  
    is serisiuly cul.

    DJ Dan's Avatar
    Join Date
    Apr 2007
    Posts
    1,324
    Thanks given
    6
    Thanks received
    5
    Rep Power
    223
    Single quotes run faster by like, nanoseconds.. The only reason that they're faster is because in double quotes PHP is checking for variables inside.

    An example that you could do is:

    $date = date("d M Y");
    echo "Hello stranger, todays date is: $date";
    Where as if you used single quotes you wouldn't be able to do that.

    Clear?
    Reply With Quote  
     

  5. #5  
    ???

    funkE's Avatar
    Join Date
    Feb 2008
    Posts
    2,606
    Thanks given
    242
    Thanks received
    977
    Discord
    View profile
    Rep Power
    1281
    Quote Originally Posted by Jub- View Post
    No, this is wrong. You are on the right track/idea but you have no clue what you are talking about.

    -----

    Single quotes run a lot faster because the computer is not attempting to execute your code when it doesn't need to.

    Double quotes run slower because the computer is attempting to execute your code inside the quotes. Double quotes are similar to the eval PHP native function.
    Stop trying to correct everyone. I am right.

    And, it doesn't act like eval, what are you talking about?


    DJ, thanks for the summary of my post, lol.
    .
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. [SERIOUS SUGGESTION]: Quotes
    By Colby in forum Suggestions
    Replies: 3
    Last Post: 12-20-2009, 05:16 AM
  2. LOL Quotes.
    By Sir John in forum Chat
    Replies: 2
    Last Post: 10-28-2009, 07:10 AM
  3. Funny quotes :)
    By Origin in forum Chat
    Replies: 1
    Last Post: 04-26-2009, 04:29 AM
  4. Quotes
    By Whitey in forum Chat
    Replies: 0
    Last Post: 02-13-2008, 08:56 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •