SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <?echo - which is correct syntax?

    Hi,

    I just wanted to check which is the correct way:

    PHP Code:
     <?
     
    <p><?php echo $var_here ?></p>
     
    ?>
    or

    PHP Code:
     <?
     
    <p><?php echo $var_here?></p>
     
    ?>
    Thanks
    coiL
    "cradled in the learning curve"

  2. #2
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't really matter. But I always put in the semi-colon...
    Oh no! the coots are eating my nodes!

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for single statements like that, i leave out the ; (and the space before ?> for that matter) to save space:

    PHP Code:
    <?php echo $var_here?>
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    SitePoint Evangelist TRISPECTIVE's Avatar
    Join Date
    Sep 2002
    Location
    n/a
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't really matter too much but you should add the ; just in case you are going to add something else in that statement and forget about the ;
    You will only get a 2 bytes larger code.

  5. #5
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Both are correct, though I too favor putting the semi-colon for the reason TRISPECTIVE expressed.

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put in both the colon and brackets. 8)

    But that's just me. It's all down to personal tastes really.


Bookmarks

Posting Permissions

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