Results 1 to 5 of 5

Thread: Today's PHP Tip

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2002
    Location
    India
    Posts
    50

    Wink Today's PHP Tip

    I am going to try and post a tip everyday.
    This one came to my mind when I saw filburt1's code on cookies:

    PHP parses strings that are enclosed in double quotes ("i will be parsed"), as opposed to those enclosed in single quotes, which are used on face value.

    So If you do
    <?php
    $somevar = 121;
    echo "I am $somevar";
    ?>

    you get
    I am 121
    If the same read
    <?php
    $somevar = 121;
    echo 'I am $somevar';
    ?>
    you get
    I am $somevar

    So as an optimization, don't put code like echo "<TR><TD>" in double quotes. Put it in single, so the PHP engine doesn't have to parse it.

    HTH
    Thanks!

  2. #2
    Nifty little tip. I forgot the String concatenation character (I thought it was + then got confused when it only printed out 0) so I had to break it up into different lines.

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    it's . arien

    echo "something " . $coolvar;

  4. #4
    Yeah, I remembered that...after two weeks of messing around with PHP

  5. #5
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    yeah, php handles string concatentaion strangely, but once you get used to it it is cool.

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width