Man, I could swear I saw it somewhere, the useful syntax for shortening the <?php echo $var ?> construct, and I think it was <?=$var?> but it doesn’t work. I’ve searched about half an hour now but can’t find the website again that told me about it, and I can’t figure out the correct syntax.
Am I hallucinating or is there really a syntax like this?
<div style="background-color:<?=$backgroundColorFromPhp?>">
Hello <?=$name?>!
</div>
PHP has the
short_open_tagdirective in php.ini which enables this syntax:as opposed to
<?php PHP code here; ?>.It also enables
as a shorthand for
<? echo variable; ?>. The docs note that as of PHP 5.4.0<?=will be enabled regardless of theshort_open_tagsetting.Very similar is
asp_tags. It enables the classic ASP-style syntax:which is where the echo-shorthand syntax originally came from. Side note: In classic ASP
<%= ...would replace the rather verbose form: