Matt's Blog

Tip of the Week: PHP Shorthand

July 26th, 2007 at 11:31 AM (17 years ago) by Matt Freedman

And here starts a little series, “Tip of the Week”. I’ll post a little tip each week. Or, at least, until I decided to stop. 😛 (PS: I changed this to Week, instead of Day… 😛 )

To save time and file size, you can use “shorthand PHP”. To use this, this must be enabled in your php.ini (turn short_open_tag to on). Although not recommended for distribuatable code (since the user might not have shorthand PHP enabled), it’s great when you need to write something quickly. You can use <? and ?> for PHP opening and closing tags. You can even use ASP-like opening/closing tags, if asp_tags is set to on. You would then be able to use <% and %>. There’s also a shorthand for echo. <?= and <%= is equivalent to <?php echo. The previously noted options must be set to on to use the shorthand for echo, respectively. For example, <?='Text';?> would do the same thing a <?php echo 'Text'; ?>.

4 Responses to “Tip of the Week: PHP Shorthand”

  1. Liam Friel
    Liam Friel says:


    I heard that <?= was going to be delimited from php – do you know anything about this?

  2. quasidynamic
    quasidynamic says:

    you me deprecated? yes, as of 5.3.0. see here:

  3. quasidynamic
    quasidynamic says:

    oops, my mistake, the deprecation warning in the php doumentation actually is referring to ‘ zend.ze1_compatibility_mode.’

    It appears short_open_tags isnt going anywhere. :)



  4. Simon Suh
    Simon Suh says:

    thanks for the quick blog post, found it through google

Leave a Reply

Quote selected text

Leave the following field empty: