Home  »  Solutions  »  What I've Learned  »  Cleaner Print Command in PHP

Cleaner Print Command in PHP

Nate Weiner - Posted in What I've Learned, Comments (3)

Stumbled upon this by accident and I haven’t been able to find anything in the PHP documentation because you can’t search for non-alpha characters, but this find has cleaned up my code a ton.

<?php print ‘Hello World’; ?>

Works the same as:

<?= ‘Hello World’ ?>

I’m using PHP 5, so I don’t know if this works in previous versions.

Comments (3)


  1. Doesn’t work in 4.4.7 :-(

    I get the error: Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’

    February 11th, 2008 Si
  2. I did some more research and found it here:
    http://php.net/language.basic-syntax

    You have to enable the short_open_tag directive in your php.ini file.
    http://php.net/manual/en/ini.core.php#ini.short-open-tag

    February 11th, 2008 Nate Weiner
  3. Hey
    It’s a bad habit - it might look cleaner, but if you’re ever going to handle/parsing XML in PHP you will be in a lot of trouble (the PHP doc mentions this as well). That’s one of the reasons that it’s not enabled by default.
    Stick to the - that’s the correct way of outputting stuff.

    Greetings
    /Rasmus

    February 14th, 2008 Rasmus Luckow-Nielsen

Leave a Reply