Results 1 to 5 of 5
  1. #1

    Default Optimizing your PHP code: Single-Quote vs Double-Quote


    Single-Quote is faster than Double-Quote...

    Why?

    because double-quote parse the string before displaying, while single-quote displays the text immediately...

    Case-Scenario:

    PHP Code:
    <?php
    $test 
    '3owz ph0wz';

    echo 
    "Test: $test";
    // Displays:
    // Test: 3owz ph0wz

    echo 'Test: $test';
    // Displays:
    // Test: $test

    ?>
    hope this simple optimization helps... ill try to create another tips for optimizing your code...
    Last edited by salbahis; 01-09-2011 at 01:43 AM.

  2. #2
    Quote Originally Posted by salbahis View Post
    Single-Quote is faster than Double-Quote...

    Why?

    because double-quote parse the string before displaying, while single-quote displays the text immediately...

    Case-Scenario:

    PHP Code:
    <?php
    $test 
    '3owz ph0wz';

    echo 
    "Test: $test";
    // Displays:
    // Test: 3owz ph0wz

    echo 'Test: $test';
    // Displays:
    // Test: $test

    ?>

    The using of quotes is fairly understandable already. If using DOUBLE QUOTES, php interprets incoming input like Variable will be parsed. SINGLE QUOTES is just strictly string. Concatenation is the common grounds of these syntaxes.

    We use both, depends on the ease of use. like this one
    Code:
    echo '<input type="text" value="'.$var1.'">';   
    // including the attribute fields of html, easier to use.
    
    echo "Hello $var_username";                         
    // mixing the variable,  easier to use.
    Last edited by dodie; 01-09-2011 at 08:55 AM.

  3. #3
    Quote Originally Posted by dodie View Post
    The using of quotes is fairly understandable already. If using DOUBLE QUOTES, php interprets incoming input like Variable will be parsed. SINGLE QUOTES is just strictly string. Concatenation is the common grounds of these syntaxes.

    We use both, depends on the ease of use. like this one
    Code:
    echo '<input type="text" value="'.$var1.'">';   
    // including the attribute fields of html, easier to use.
    
    echo "Hello $var_username";                         
    // mixing the variable,  easier to use.
    yes its case-2-case scenario but it can be remedied if you break it by using "\"

    PHP Code:
    <?php
    $sql 
    'SELECT * FROM db_table WHERE ID=\''.$id.'\' LIMIT 0,3';

    $sql "SELECT * FROM db_table WHERE ID='".$id."' LIMIT 0,3";

    ?>
    then again it still depends on the coder which to choose and what situtation dictates...

    for me most of the times i limit my self using single-quote due to the structure of the site, that it loads very slow...

  4. #4
    if you're using more than one programming language it's best to use standard concatenation technique
    using this it's easy to debug run-time errors relating to concatenation.
    you will separate the value from the string.

    basic examples:

    //php
    e.g. echo "Display the string with value = ".$valuehere;

    //java
    System.out.println("Display the string with value = "+valuehere);

    //VB
    Debug.print "Display the string with value = " & valuehere


    or in any case you can apply what TS wrote
    Last edited by sanggano_boy; 01-10-2011 at 10:28 AM.

  5. #5
    up ko ani pra mapun-an pa..

  6.    Advertisement

Similar Threads

 
  1. An Inquiry on PHP code optimization
    By carmicael in forum Programming
    Replies: 8
    Last Post: 08-13-2009, 10:35 PM
  2. DDR? which is best (single-sided or double sided) ?
    By rAge in forum Computer Hardware
    Replies: 3
    Last Post: 05-24-2007, 06:55 PM
  3. Php code
    By tjyrna in forum Programming
    Replies: 2
    Last Post: 09-06-2006, 04:54 PM
  4. i need link searcher php code
    By siegfredb in forum Websites & Multimedia
    Replies: 4
    Last Post: 04-14-2006, 12:44 AM
  5. Replies: 35
    Last Post: 03-10-2006, 11:50 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
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top