This question already has an answer here:
这个问题在这里已有答案:
- Why when add <?xml version=“1.0” encoding=“utf-8”?> to web page don´t work on hosting? 1 answer
- 为什么在将<?xml version =“1.0”encoding =“utf-8”?>添加到网页时不能进行托管? 1个答案
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.log
I'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?这可能是由特定的扩展引起的吗?
3 个解决方案
#1
30
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_tag
in php.ini to 0
or Off
and restart Apache.
将php.ini中的config选项short_open_tag设置为0或Off并重新启动Apache。
#2
1
Did you check if short tags are enabled/disabled on php.ini?
您是否检查过php.ini上是否启用了短标签?
#3
1
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
您应该使用PHP XML库,如http://de.php.net/manual/en/book.dom.php
#1
30
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_tag
in php.ini to 0
or Off
and restart Apache.
将php.ini中的config选项short_open_tag设置为0或Off并重新启动Apache。
#2
1
Did you check if short tags are enabled/disabled on php.ini?
您是否检查过php.ini上是否启用了短标签?
#3
1
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
您应该使用PHP XML库,如http://de.php.net/manual/en/book.dom.php