PHP 解析错误 - 意外的 T_STRING
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10506057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Parse error - unexpected T_STRING
提问by Marco
In Windows (WAMP) I have an index.php like this
在 Windows (WAMP) 中,我有一个这样的 index.php
<?xml version="1.0" encoding="utf-8"?>
<?php
// ...
?>
and it works as expected.
Now I've just configured a LAMP on Ubuntu and the same file (when invoked from a browser) gives me an error. Looking in error.logI've found
它按预期工作。
现在我刚刚在 Ubuntu 上配置了一个 LAMP,同一个文件(从浏览器调用时)给了我一个错误。看着error.log我发现
PHP Parse error: syntax error, unexpected T_STRING in /var/www/test/index.php on line 1
PHP 解析错误:语法错误,第 1 行 /var/www/test/index.php 中的意外 T_STRING
If I remove first line everything works fine.
What's wrong? Why this works on Windows and not on Linux?
Could this be caused from a particular extension?
如果我删除第一行,一切正常。
怎么了?为什么这适用于 Windows 而不适用于 Linux?
这可能是由特定扩展引起的吗?
回答by nickb
It sounds like you have short tags enabled, which will cause PHP to try and parse what comes after <?.
听起来您启用了短标签,这将导致 PHP 尝试解析<?.
Set the config option short_open_tagin php.ini to 0or Offand restart Apache.
将short_open_tagphp.ini 中的配置选项设置为0orOff并重新启动 Apache。
回答by gunnx
Did you check if short tags are enabled/disabled on php.ini?
您是否检查过 php.ini 上是否启用/禁用了短标签?
回答by Dmitry
It's not a good idea to work with XML as a string.
将 XML 作为字符串处理并不是一个好主意。
You should use php XML libraries like http://de.php.net/manual/en/book.dom.php
您应该使用像http://de.php.net/manual/en/book.dom.php这样的 php XML 库

