Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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?

share|improve this question

marked as duplicate by Alexander, Ocramius, Gordon, hakre, Jocelyn Mar 5 '13 at 12:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I think the short tags answers will work; in my experience, I've always echoed the <?xml ... ?> string from PHP code so I didn't have to worry about how short tags were set. – Crontab May 8 '12 at 20:45
    
echo '<?xml version="1.0" encoding="UTF-8" ?>'; – Hosam alzagh Feb 19 at 14:14
up vote 21 down vote accepted

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.

share|improve this answer
2  
A silly mistake that took me a lot of time: thanks a lot!!! – Marco May 8 '12 at 20:50

Did you check if short tags are enabled/disabled on php.ini?

share|improve this answer
    
Thanks for your help!! I appreciate so much – Marco May 8 '12 at 20:50

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

share|improve this answer
1  
echo '<?xml version="1.0" encoding="UTF-8" ?>'; – Hosam alzagh Feb 19 at 14:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.