Jump to content

PHP and XML Declaration


23.12.2012

Recommended Posts

Today, I switched from using my OS's default installation of PHP and Apache to an AMP package (namely, MAMP). Before, I would have had something like this working perfectly:

<?php// SOME PHP?><?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">	<head>		<title>Page Title</title>	</head>	<body>		<h1>Hello, World!</h1>	</body></html>

But after the switch, I get the following error:

Parse error: syntax error, unexpected T_STRING in 'SCRIPT' on line 'x'

I removed the XML declaration line, refreshed, and it worked perfectly again. Could you explain me why that is? The OS has Apache 2.2.14 and PHP 5.3.1, while MAMP has Apache 2.0.63 and PHP 5.3.2. The php.ini files are nearly identical, with the MAMP one having some different locations in its path.

Link to comment
Share on other sites

I suspect short tags are enabled on your new server. That permits a opening PHP tag to look like this: <? and that's it. The php can be left out. So the PHP interpreter might think your XML declaration is a PHP tag. I believe this is a common problem.See if short tags are enabled and then disable them. I think that's the short_open_tag directive. So maybe add a line to your ini file like this:short_open_tag=off

Link to comment
Share on other sites

Yes, that did the trick. Thanks a lot! I was suspecting a headers problem at first, but it did not seem like one.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...