Forum Moderators: open
Eg:
<?xml version="1.0" encoding="UTF-8"?> But if I do this in a php file, I get a parse error on that line. Do I need the line? Or is using php not proper XHTML anyway?
Another cure is to use PHP to output the <?xml declaration in a print or echo statement.
There's no problem (other than that) with using PHP in conjunction with XHTML. You are using PHP to create an XHTML file: the browser doesn't care how the XHTML file was generated, as long as it's valid. If you View Source and see a valid XHTML file, it's a valid XHTML file whether you typed it in yourself or used PHP, ASP, Perl or even ROCProL (rewboss' Own Cool Programming Language) to output it.
Great! But what happens if the document is read by a device which doesn't have PHP? It won't recognize it as XML. So the document becomes platform specific, surely not the idea of XML documents?
This is true, a PHP document is not an XML document. The output of the PHP document will be an XML document though, and will be portable.
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> It fails to consider it as XML, and moves on.
Solution?
OK, so a device such as a spider finds the document on the server, and comes across this line:<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
It fails to consider it as XML, and moves on.
Solution?
Okay, maybe I'm ignorant here, but I don't see the problem.
Spider requests page from server. Server gets request, parses php file, and serves spider XHTML. Spider reads XHTML, and moves on.
No php source will be sent, since PHP server-side scripting.
Now, if you don't have php enabled on the server, that would be a problem. But then why are these php pages then?
If you are using templates, even a primitive one like mine, no URL ever points to a file that outputs anything, let alone valid XHTML.
If you're worried about what would happen if some malicious sysadmin suddenly removed PHP from your system and you started sending out php source, I would say
- for most files, who cares, unless you have some absolutely ingenious script that you don't want anyone to see? Considering the number of freely available PHP scripts out there, that's pretty unlikely.
- for files holding passwords (such as to open a connection to a database), put them in a directory that is outside the directory tree and is not publicly readable. If your setup allows, it's best to put that stuff outside of your web tree altogether, like in /usr/local/etc or something like that. No file that ever has a URL pointing to it should include that stuff IMHO
Tom
When PHP is installed on the server, any file with a .php extension will be parsed when it is requested but before it is sent to the device -- whether said device is a browser or a spider.
Imagine you have a PHP document that looks like this:
<html>
<head><title>Test</title></head>
<body>
<?php
echo "<h1>Hello, world</h1>";
?>
</body>
</html>
A spider requests the document. PHP sees the .php extension on the file name, and knows that it has to parse the file. It does so, executing any PHP statements it finds before letting the spider see the document. The spider then receives the following file:
<html>
<head><title>Test</title></head>
<body>
<h1>Hello, world</h1>
</body>
</html>
It doesn't see any PHP at all. Spiders request files in the same way that browsers do.
"Warning: DOCTYPE Override in effect! Any DOCTYPE Declaration in the document has been supressed and the DOCTYPE for «XHTML 1.0 Transitional» inserted instead. The document will not be Valid until you alter the source file to reflect this new DOCTYPE."
This is nonsense, as I'm using the DTD supplied by the W3C! It replaces the one I had with exactly the same thing! All I can think is that the XML declaration above it is at fault, but again, I am copying code from the W3C. Or should it be on the second line after the DTD?
Also, I've noticed one page I have now has an extra line space in it, and tighter line-height in one cell. Huh!?!? Does the XML declaration do something to the browser? (IE6, W98)
- let it find the DOCTYPE
- force it to validate to a specific DOCTYPE.
If you choose the latter, you are overriding your document's DOCTYPE, even if you are overriding it with the exact same DOCTYPE. What it's telling you is that your DOCTYPE is being ignored, not that it's incorrect.
If you choose auto-detect, it should use your DOCTYPE
In other words, you are submitting the form incorrectly, but there is nothing wrong with the W3C validator and there may be nothing wrong with your document.
Tom