Tip of the Week: PHP Shorthand
July 26th, 2007 at 11:31 AM (17 years ago) by Matt FreedmanAnd 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'; ?>
.
Find something useful here? Feel free to help me out by sending a donation. :)
4 Responses to “Tip of the Week: PHP Shorthand”
Leave a Reply
November 24th, 2008 at 2:53 AM | Quote Comment
Hi,
I heard that <?= was going to be delimited from php – do you know anything about this?
September 29th, 2010 at 1:10 PM | Quote Comment
you me deprecated? yes, as of 5.3.0. see here:
http://php.net/manual/en/ini.core.php
September 29th, 2010 at 1:19 PM | Quote Comment
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.
Cheers,
q
November 3rd, 2011 at 7:55 PM | Quote Comment
thanks for the quick blog post, found it through google