If everything else in the php code is correct, omit the Doctype at the
very top of the page and start with the php which may be an include if
you are going to use this for several pages. Then use the php to write
the Doctype near the end of the php code. If you do absolutely
anything before the header conversation between the server and
browser, then it is too late to mess with the header exchange. To
check the page at the W3C validator, go to the page and right click,
select to view source code, and copy. Then paste this in the box for
direct code input at the W3C validator rather than using a url.
Sometime a url pasted in will work correctly for a php page, sometimes
not, and sometimes you use header exchange to generate any one of
several possible pages, depending on what is found. A html page that
has some php usually should have the extension .php rather than .html
or .xhtml.
Perhaps an example of how you write the Doctype in the php at the very
top of the page will help. My example will write one of two possible
Doctypes depending on what the header exchange finds - xhtml 1.1 or
html 4.01 strict. Your other code of course will be different from
mine, depending on exactly what you are doing with the php in the
header exchange.
<?php
$charset = "UTF-8";
function fix_code($buffer) {
return (preg_replace("!\s*/>!", ">", $buffer));
}
if (stristr($_SERVER[HTTP_ACCEPT], "application/xhtml+xml") ||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator") )
{
$mime = "application/xhtml+xml";
$prolog_type = "<?xml version=\"1.0\" encoding=\"$charset\" ?>\n<!
DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"
http://www.w3.org/
TR/xhtml1/DTD/xhtml11.dtd\">\n<html xmlns=\"
http://www.w3.org/1999/
xhtml\" xml:lang=\"en\">\n";
header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");
print $prolog_type;
}
else
{
$mime = "text/html";
ob_start("fix_code");
$prolog_type = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//
EN\" \"
http://www.w3.org/TR/html4/strict.dtd\">\n<html lang=\"en\">
\n";
header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");
print $prolog_type;
}
?>
Writing a code with php is much like writing code with docuent.write
using JavaScript, but there are enough differences to get you into
trouble if you are not careful.
Thanks for the suggestion as well as the sample code.. Appreciate you
taking the time. I'm sure it will fix my problem..
Bruce