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
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.
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
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>
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
XHTML Standards, PHP and stuff
Yes, any file containing PHP code will need to have the .php extension.
XHTML Standards, PHP and stuff
The other option is to have
<?php print"<?xml... "; ?>
as the first line.
XHTML Standards, PHP and stuff
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
XHTML Standards, PHP and stuff
I took leave of my senses... I have my own php files on my server set .co2! Oops!
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
Good tip there Trevor, I need to experiment on that
Jeffery