9 replies [Last post]
MalphasWats
Offline
Regular
Last seen: 8 years 4 weeks ago
Joined: 2004-03-22
Posts: 45
Points: 0

Hi, I was playing around with my site prototype last night and I came up with a layout that I'm happy with. I then decided to try out some of the php stuff that I intend to use to drive it but I found that the whole thing went completely to poo.

I tracked it down to the <?xml... part at the beggining, the <? bit was being processed by the php interpreter.

Is it actually possible to write standards compliant webcode that contains PHP, or is this a no-no before I've even started?

I'm completely new to the idea of the various xml standards, I've read through a few bits on w3.com but it doesn't seem to make a huge amount of sense to me yet.

The main reason I'm using PHP is because my site ended up with indenticle html code all over with differences between a 'content' div, so I thought I'd just generate this bit with PHP rather than keep duplicating code all over (I'm a software engineer by trade, it's just not right!).

What's the accepted convention for this situation?

Thanks
-Mal

http//www.michael-watts.com

"Never put your face in a bag of angry squirrels"

Tags:
co2
co2's picture
Offline
Leader
UK
Last seen: 6 years 32 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

XHTML Standards, PHP and stuff

Don't worry, you can happily use PHP with standard code (in fact, PHP is a fantastic server-side language for such integration).

The xml tag you refer to is a known problem. It comes before the DOCTYPE declaration and takes the form of:

<?xml version="1.0" encoding="utf-8"?>

The solution is simple... delete it. I haven't heard of it confusing PHP parsing before (sort of makes sense I suppose), but worse still IE(6) doesn't like the xml declaration. The accepted thing to do is to remove it completely from your code, since it doesn't do much (if anything) anyway.

There are plenty of discussions around about the declaration (but I can't find one right now!)... J Zeldman also documents it in his book Designing With Web Standards.

The next sentence is true. The previous sentence is false. Discuss...

MalphasWats
Offline
Regular
Last seen: 8 years 4 weeks ago
Joined: 2004-03-22
Posts: 45
Points: 0

XHTML Standards, PHP and stuff

Thanks, I did try it last night, but it seemed to affect my browser from loading my CSS file properly (or at least interpreting it properly) - some of the styles were missing. In the end I deleted the <doctype...> tag along with the xml one and it worked.

Was this second problem really something else?

I'll try it all again if I get a chance tonight.

Thanks
-Mal

http//www.michael-watts.com

"Never put your face in a bag of angry squirrels"

co2
co2's picture
Offline
Leader
UK
Last seen: 6 years 32 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

XHTML Standards, PHP and stuff

No, I don't think that would've been your problem. I've always used XHTML 1.0 Transitional and Strict DOCTYPEs without the XML declaration. Never caused a CSS linking/style problem.

Generally, this is the first few lines I use in my HTML files:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>Untitled</title>
</head>
<body>

The next sentence is true. The previous sentence is false. Discuss...

MalphasWats
Offline
Regular
Last seen: 8 years 4 weeks ago
Joined: 2004-03-22
Posts: 45
Points: 0

XHTML Standards, PHP and stuff

thanks, I'll try it again - probably a silly question, but does it matter that the files have to have the .php extension on the server I use in order for the php processor to execute any code in there?

ta
-Mal

http//www.michael-watts.com

"Never put your face in a bag of angry squirrels"

co2
co2's picture
Offline
Leader
UK
Last seen: 6 years 32 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

XHTML Standards, PHP and stuff

Yes, any file containing PHP code will need to have the .php extension.

The next sentence is true. The previous sentence is false. Discuss...

dJomp
dJomp's picture
Offline
Enthusiast
York, England
Last seen: 11 years 35 weeks ago
York, England
Joined: 2003-03-23
Posts: 422
Points: 0

XHTML Standards, PHP and stuff

The other option is to have
<?php print"<?xml... "; ?>
as the first line.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 2 years 22 weeks ago
A hilly place, UK
Timezone: GMT+1
Joined: 2004-02-05
Posts: 2902
Points: 0

XHTML Standards, PHP and stuff

co2 wrote:
Yes, any file containing PHP code will need to have the .php extension.

Hi co2

Not quite true. Apache will pass any extension you want to the php parser as long as you tell it too.

If you have access to the httpd.conf file, look for this line:

AddType application/x-httpd-php .php .php3 .php4 .phtml

and add the extension you want (like html, etc).

The only problem is that it adds to the server load an you need access to the conf file. It is also possible to do it in the .htaccess file, but for it to work, another setting needs to be made in the httpd.conf file.

Just as a laugh, I once set up png's to be parsed, and then renamed my php gd files as png. They worked fine and produced images as required.

Trevor

co2
co2's picture
Offline
Leader
UK
Last seen: 6 years 32 weeks ago
UK
Joined: 2003-09-17
Posts: 721
Points: 0

XHTML Standards, PHP and stuff

I took leave of my senses... I have my own php files on my server set .co2! Oops!

The next sentence is true. The previous sentence is false. Discuss...

paCkeTroUTer
paCkeTroUTer's picture
Offline
Enthusiast
Melbourne, Australia
Last seen: 1 year 28 weeks ago
Melbourne, Australia
Timezone: GMT+10
Joined: 2003-06-27
Posts: 241
Points: 2

XHTML Standards, PHP and stuff

ClevaTreva wrote:
co2 wrote:
Yes, any file containing PHP code will need to have the .php extension.

Hi co2

Not quite true. Apache will pass any extension you want to the php parser as long as you tell it too.

If you have access to the httpd.conf file, look for this line:

AddType application/x-httpd-php .php .php3 .php4 .phtml

and add the extension you want (like html, etc).

The only problem is that it adds to the server load an you need access to the conf file. It is also possible to do it in the .htaccess file, but for it to work, another setting needs to be made in the httpd.conf file.

Just as a laugh, I once set up png's to be parsed, and then renamed my php gd files as png. They worked fine and produced images as required.

Trevor

Good tip there Trevor, I need to experiment on that Smile
Jeffery

http//melbourne.ug.php.net