• 2nd May 2010 - By iKode

    When coding in PHP you must specify where the PHP code begins and ends by using tags.  PHP tags come in two flavors, full and short tags. Below is a sample of using full tags.

    Full Tags

    <?php
    echo "This is PHP";
    ?>

    Below is a sample of PHP using short tags.

    Short Tags

    <?
    echo "This is PHP";
    ?>

    There is a setting in the PHP.INI file that will determine if your server can use short tags.  Depending on the server configuration it may or may not be turned on.  If short_open_tag is not turned on the server will server up the PHP code as plain text which could be a security risk.

    short_open_tag = On

    Although both versions are technically correct,  full tags should always be used.  Some will argue that using short tags is quicker , and yes although it may save you 3 keystrokes today, tomorrow it may cause headaches.

    There are many times that you will need to share your code.  Because PHP is an easy language to learn , most people don’t go beyond the basics.  I often see complaints that the server is not “working” because they can see the PHP code being served up.   They cannot understand why they see the PHP code in the browser.  Most of the time this is due to the script using short tags.  In most cases the user has no clue that there is a php.ini file let alone a short_open_tag.

    Why take the chance , always use full PHP tags that are guaranteed to work 100%.

  • Leave a Reply

    Spam protection by WP Captcha-Free


PHVsPjxsaT48c3Ryb25nPndvb19hZF9mb290ZXI8L3N0cm9uZz4gLSBmYWxzZTwvbGk+PGxpPjxzdHJvbmc+d29vX2FkX2Zvb3Rlcl9hZHNlbnNlPC9zdHJvbmc+IC0gPC9saT48bGk+PHN0cm9uZz53b29fYWRfZm9vdGVyX2ltYWdlPC9zdHJvbmc+IC0gaHR0cDovL3d3dy53b290aGVtZXMuY29tL2Fkcy93b290aGVtZXMtNDY4eDYwLTIuZ2lmPC9saT48bGk+PHN0cm9uZz53b29fYWRfZm9vdGVyX3VybDwvc3Ryb25nPiAtIGh0dHA6Ly93d3cud29vdGhlbWVzLmNvbTwvbGk+PGxpPjxzdHJvbmc+d29vX2FsdF9zdHlsZXNoZWV0PC9zdHJvbmc+IC0gZGVmYXVsdC5jc3M8L2xpPjxsaT48c3Ryb25nPndvb19hdXRvX2ltZzwvc3Ryb25nPiAtIGZhbHNlPC9saT48bGk+PHN0cm9uZz53b29fY2F0X2NvbG9yXzE8L3N0cm9uZ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