Link to home
Start Free TrialLog in
Avatar of ruud00000
ruud00000

asked on

html page returns server error on php server

When I open a simple HTML page on Apache, using usbwebserver 7.0 (www.usbwebserver.com)  I get a server error.
One problem seems to be the <?xml version="1.0"encoding="UTF-8"?> line. If I type only the php tag within the simple <html> and <body>  tags there's no server error, as soon as I add the <?xml> tag I get a server error.
Is there a settng I can change in one of the server setting files to make this work?
Setting files are enclosed.


<?xml version="1.0"encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>	... </title>
	</head>
	<body>
		<p>
			<?php
			print("hallo PHP wereld!"); 
			?>
		</p>
	</body>
</html>

Open in new window

settings.ini
settings.txt
settings.ini
php.ini
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

<?xml version="1.0"encoding="UTF-8"?> is used for serving up XML documents.  XHTML pages do not use that.  Acceptable DOCTYPES for 'text/html' are listed here:
http://www.w3.org/QA/2002/04/valid-dtd-list.html
Avatar of tv0085
tv0085

There is a setting in php.ini.
change
short_open_tag = On
to
short_open_tag = Off

; Allow the <? tag.  Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
Avatar of ruud00000

ASKER

I tried that, no change.
This works fine.  Displays 'hallo PHP wereld!' twice.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>	... </title>
	</head>
	<body>
		<p>
			<?php
			echo("hallo PHP wereld!"); 
			print("hallo PHP wereld!"); 
			?>
		</p>
	</body>
</html>

Open in new window

By the way, this has to be saved as 'myfile.php' with the php extension for it to be processed thru the PHP interpreter.  It won't work as 'myfile.html'.
Hello Dave,

The code you provided works fine, since the
<?xml version="1.0"encoding="UTF-8"?>  
line is not included.
However when this is included (see question) the problem arises, also (NOT to be expected) when short_open_tag is set to 'Off' in php.ini.

If I understand your answer well you say I shouldn't want to use xml commands in a XHTML document when using PHP, but the whole idea of using the <?php instead of the short tag <? is that is should work well also in combination with xml commands? Correct me if I'm wrong.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
don't feel my question was answered
I'm sorry you don't feel your question was answered.  There are a lot of details about both XML and XHTML and PHP on http://www.w3schools.com/ .  I refer to them a lot because they list almost ever command and format available for a lot of web technologies.  

XML and XHTML are not interchangeable and you can't use the headers or DOCTYPEs interchangeably either.  Yes, you should use long tags <?php with XML because the XML header tag <?xml  contains a short tag and your php could confuse the two if you didn't.