开发者

PHP syntax issue

I have just downloaded a PHP blog script and am having a few issues with the syntax used in it.

There are several instances when this code occurs:

<?=$miniblog_posts?>

Now this doesn't do anything. To get it to work I have to change it to this.

<?php echo $miniblog_posts; ?>

Is this an old way of writting php that is n开发者_如何学编程ot supported anymore or am I missing something.

I am running PHP V5.3.1


http://php.net/manual/en/function.echo.php

See the shortcut syntax doc.

echo() also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. This short syntax only works with the short_open_tag configuration setting enabled.


Yeah it's called short open tags and now are disabled by default. You can change your configuration to enable them but it's not recommended, cause they will be removed from PHP next version (probably in php 5.4)

Configuration and severals stuffs are detailed in this page : http://php.net/manual/ini.core.php


You have to enable short tag in php.ini to make <?=$miniblog_posts?> workable.

short_open_tag=On

Here are some related posts which may also help you to understand this:

  • shorter way of echoing a variable in php?
  • php variable in html no other way then: <?php echo $var; ?>
  • Are PHP short tags acceptable to use?


I think you may need to turn on short_open_tag in php.ini file. Or you can config at .htaccess . Like

short_open_tag on 


The PHP Shorthand notation <?= ?> depends on the php.ini, you should change the state to allow short open tag. Whereas the code <?php ?> can run everytime everywhere, without any configuration.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜