16

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?

hakre
  • 184,866
  • 48
  • 414
  • 792
Marco
  • 55,302
  • 13
  • 128
  • 150

3 Answers3

41

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.

nickb
  • 58,150
  • 12
  • 100
  • 138
3

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

Dmitry
  • 7,227
  • 12
  • 56
  • 81
1

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

gunnx
  • 1,229
  • 6
  • 16