Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Parse error - unexpected T_STRING [duplicate]

Tags:

php

xml

In Windows (WAMP) I have an index.php like this

<?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

PHP Parse error: syntax error, unexpected T_STRING in /var/www/test/index.php on line 1

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?

like image 905
Marco Avatar asked May 08 '12 20:05

Marco


2 Answers

It sounds like you have short tags enabled, which will cause PHP to try and parse what comes after <?.

Set the config option short_open_tag in php.ini to 0 or Off and restart Apache.

like image 65
nickb Avatar answered Oct 10 '22 08:10

nickb


It's not a good idea to work with XML as a string.

You should use php XML libraries like http://de.php.net/manual/en/book.dom.php

like image 38
Dmitry Avatar answered Oct 10 '22 06:10

Dmitry