问题
I'm running on windows 7 with php 5.3.1. some of the examples I see on the internet uses short tags instead of echo.
so why doesn't this work
<td><?=$row['name'];?></td>
but this works?
<td><?php echo $row['name'];?></td>
回答1:
Try this in you php.ini
short_open_tag=On
Then restart your server
回答2:
As of PHP 5.4 the shorthand for echo that you are showing is enabled by default. Prior to that it must be enabled in the configuration via the short_open_tag directive.
It is changable PHP_INI_PERDIR
meaning that is can be set in the php.ini, server config or in .htaccess
回答3:
Short tag or short_open_tag
for some server is not enabled by default, and it is encourage to use the actual regular tag <?php
because of the reason that if you want to do some migration from one server to another and if the other doesn't support it will break everything.
回答4:
It is because short_open_tag
is disabled.
Open your php.ini
file and set short_open_tag
to 1
. Save the file and restart your web server.
回答5:
You need to enable short tags in your php.ini
and restart your server as said by User016.
short_open_tag=On
It's been recommended not to use the short tag "short cut" and instead to use the full <?php and ?> tag combination. With the wide spread use of XML and use of these tags by other languages, the server can become easily confused and end up parsing the wrong code in the wrong context. Also short tags may not be supported on the target server
来源:https://stackoverflow.com/questions/17961367/short-tags-not-working