Coding PHP, the most used server side language on the Web (WordPress being the best proof of it) usually ends up in mixing its code with HTML, what leads to a nasty result, specially when you need to call short pieces of PHP code inside HTML all the time.
There been a few ways to tell the PHP parser when to start and stop interpreting the PHP code, however most been deprecated for compatibility reasons, but the good news are that PHP Short Tags are a reality in latest versions.
The most used is the Short echo Tag <?="string" ?>
(always available since version 4.6), is the same as having the typical full tag with the echo command <?php echo "string"; ?>
. On this less verbose tag <?= ?>
the ending statement ;
is not required.
Other Short Tag that is less used, is the <? ?>
to replace the more verbose original PHP Tag <?php ?>
, but for this to work you have to edit the php.ini
and enable short_open_tag
by changing it from off
to on
and then restart your webserver service/daemon (Apache). Please note that if you enable this option and code all your PHP with the Short Tag, then when you upload or distribute your code to other servers, if the php.ini
file short_open_tag
is not set to on
, your code wont be executed. For this reason many coders do not use it but lately more and more Web Servers come with this option enabled, however keep in mind that is not a rule to have it enabled by default.
If you have any questions, just comment and I will do my best to help you.
Leave a Reply