开发者

What does <?= mean? [duplicate]

开发者 https://www.devze.com 2022-12-14 23:45 出处:网络
This question already has answers here: 开发者_如何学运维 What does '<?=' mean in PHP?
This question already has answers here: 开发者_如何学运维 What does '<?=' mean in PHP? (8 answers) Closed last year.

whats the meaning of this line

<input type=text name="name" value="<?= $name ?>

if we are to declare as PHP shouldn't we write <?php instead of <?=

Thanks


<?= are PHP short open tags, which can be enabled (or disabled) via the short_open_tag directive in php.ini (quoting) :

This directive also affects the shorthand <?= , which is identical to <? echo . Use of this shortcut requires short_open_tag to be on.

And:

Also if disabled, you must use the long form of the PHP open tag (<?php ?> ).

This means your portion of code :

<input type=text name="name" value="<?= $name ?>

Is equivalent to this one :

<input type=text name="name" value="<?php echo $name; ?>

But only when short open tags are enabled.

And, as a sidenote : short open tags are not always enabled -- in fact, they are disabled by default, with recent versions of PHP.

Which means it might be wise to not depend on those, at least if you want to deploy your application on servers on which you are not administrator.


<?= ... ?> is shorthand for <?php echo ... ?>


using short tags is generally frowned upon nowadays but it's still an option in the php.ini. It's fine, it's just poor coding style and has some repercussions if you use multiple dynamic languages.

0

精彩评论

暂无评论...
验证码 换一张
取 消