OK firstly, I added this line to my .htaccess file so the php engine parses php code in .xml file:
AddType application/x-httpd-php .php .php3 .phtml .html .xml
After that when I view an .xml file I get this PHP error:
Parse error: parse error, unexpected T_STRING in /var/www/vhosts/mydomain.com/httpdocs/test.xml on line 1
But line 1 is not even php infact this is line 1:
<?xml version="1.0" encoding="utf-8"?>
Can anyone tell me what the problem is?
Here is Solutions:
We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.
<? is the short opening tag for php.
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
Yeah, sad but true, it’s the doctype being seen as the PHP opening short tag. You have a few options:
- Take XML out of the list of files for PHP to parse in the .htaccess file
Wrap all of your xml declarations in PHP:
<?php print('<?xml version="1.0" encoding="utf-8"?>'); ?>
short_open_tagin .htaccess or the php.ini. This means that PHP will only accept
<?phpas an opening tag and will ignore
Alternative 4, in addition to daniel’s: drop the <?xml…?> declaration completely.
Since ‘1.0’ and ‘utf-8’ are the defaults for XML, it’s completely redundant; including the XML declaration here gains you nothing.
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂