[英]PHP echo printing additional characters
I can class myself as a mid level PHP user, I have recently installed XAMPP on a new PC and noticed a strange behaviour while trying to run a simple php script. 我可以将自己分类为中级PHP用户,最近我在新PC上安装了XAMPP,并在尝试运行简单的php脚本时注意到一种奇怪的行为。 This is my script:
这是我的脚本:
<?
$data_to = "<b>Line Print</b>";
?>
<? echo($data_to); ?>
And this is what I am getting on the browser 这就是我在浏览器上得到的
Line Print"; ?>
行打印”;?>
Can some one please explain why? 有人可以解释一下原因吗?
Short opening tags ( <?
) are disabled in php.ini. 在php.ini中禁用了短标签(
<?
)。 Either edit PHP configuration or use <?php
. 编辑PHP配置或使用
<?php
。
http://www.php.net/manual/en/ini.core.php#ini.short-open-tag http://www.php.net/manual/zh/ini.core.php#ini.short-open-tag
SOLUTION 1: 解决方案1:
short_open_tag=On
in php.ini and restart your Apache server. 在php.ini中,然后重新启动Apache服务器。
SOLUTION 2: 解决方案2:
Use the <?php
tags completely because <?
完全使用
<?php
标记是因为<?
is not recommended. 不推荐。
If you ever have to move your code to a server where it's not supported (and you can't enable it), then you're doomed. 如果您不得不将代码移动到不支持(无法启用)的服务器上,那么您就注定了。 It's better to use the full syntax.
最好使用完整语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.