<?php or <? Simple Question

Discussion in 'PHP' started by wd_2k6, Jun 26, 2009.

  1. #1
    Hi,

    I've been running through a few tutorials and examples, and i've noticed that some use different methods to open their code blocks:

    [B]<?php[/B]
    
    //PHP Code
    
    [B]?>[/B]
    Code (markup):
    Whereas some use:

    [B]<?[/B]
    
    //PHP Code
    
    [B]?>[/B]
    Code (markup):
    Is there any difference, advantages or disadvantages?
     
    wd_2k6, Jun 26, 2009 IP
  2. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    stick with <?php

    there are no advantages or disadvantages, but some settings on the server might not translate <? as an opening tag for php.
     
    zeronese, Jun 26, 2009 IP
    wd_2k6 likes this.
  3. 4u-domains

    4u-domains Member

    Messages:
    89
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #3
    Yeah, you can't go wrong with <?php ..... ?>

    <?....?> is known as a short tag and there is a possibility of some servers having an issue but then again, the vast majority of our sites running php scripts use <? and we have NEVER had a problem. I've never seen it as an issue in all my years and just about every hosting company are cool with it on their servers. (short_open_tag value to On in the PHP configuration file php.ini)

    Incidently there are two other ways of enveloping php content:
    <script language="php"> ---- </script>
    and
    <% ... %>
    :eek:

    If you are writing php from scratch then definately use the <?php tag
    BUT if you are considering rewriting an existing script becuase of concerns then there is not real need to do this.
     
    4u-domains, Jun 26, 2009 IP
    wd_2k6 likes this.
  4. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the info guys, it's appreciated.
     
    wd_2k6, Jun 26, 2009 IP
  5. windy

    windy Active Member

    Messages:
    1,093
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #5
    <?....?> is almost the same as <?php ..... ?>, but <?php ..... ?> has advantage that it can be used on more platform
     
    windy, Jun 27, 2009 IP
  6. dweebsonduty

    dweebsonduty Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #6
    I agree <?php is just 3 more letters and it works on more platforms, no guessing.
     
    dweebsonduty, Jun 27, 2009 IP
  7. ItamarP

    ItamarP Member

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    <?php ?> can be used in more platforms ,dont be lazy it's all about 3 more letters ;)
     
    ItamarP, Jun 27, 2009 IP
  8. Love*

    Love* Well-Known Member

    Messages:
    1,739
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    165
    Digital Goods:
    1
    #8
    <?php ?> is always better. :)
     
    Love*, Jun 27, 2009 IP
  9. arthur.x

    arthur.x Banned

    Messages:
    568
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I would join to already made opinion but also add that I have never came across hosting where <? ?> are set to be off :)
    a lot of php-coders use <?=$var;?> instead of <?php echo $var; ?>
     
    arthur.x, Jun 27, 2009 IP
  10. servicedb

    servicedb Peon

    Messages:
    146
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    <?php=$var; ?> will also work
    Anyway, when you program something, use <?php because some web servers won't support <? (like a default install with XAMP, but I would never use XAMP on public web servers).
     
    servicedb, Jun 27, 2009 IP