Menu
My question is simple
I’m about to start to develop a new web site.
Is it worth taking the time to make it validate against the W3C XHMTL validator or would HTML 4 be fine?
In doing so will my site be more user friendly with other browsers?
<i>
</i><?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?>
and for ASP:<i>
</i>if InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 then
Response.ContentType = "application/xhtml+xml"
else
Response.ContentType = "text/html"
end if
In both cases the code must go at the very start of the document, b before any code has been sent to the browser (even if it's just a line break).<i>
</i><meta http-equiv="content-type" content="application/xhtml+xml;charset=windows-1252" />
But then you also need some server side code that tells the browser to interpret what it's receiving is application/xhtml+xml (so long as the browser can handle it). The code detects whether the browser can handle application/xhtml+xml and if it can't it tells the browser that it's sending normal text/html.<i>
</i>
<%
if InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") > 0 then
Response.ContentType = "application/xhtml+xml"
else
Response.ContentType = "text/html"
end if
Response.Charset="windows-1252"
sub top(title) %><?xml version="1.0" encoding="windows-1252"?>
<!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" xml:lang="en">
<head>
<title>Hackus<%= title %></title>
<meta http-equiv="content-type" content="application/xhtml+xml;charset=windows-1252" />
<style type="text/css" media="all">
@import "styles.css";
</style>
</head>
<body>
<% end sub %>
[i]Originally posted by lavalamp [/i]
[B]Here's the code for PHP:
[/B][/QUOTE]
<i>
</i><?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") [color=blue]||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))[/color]
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?>
[i]Originally posted by Paul Jr [/i]Well the red part certainly is:
[B]Is the part in blue really necessary? Unless there's some obfuscated reason, I can't see why it'd be necessary... [/B][/QUOTE]
<i>
</i>
<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") [color=blue]||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator")[/color][color=red])[/color]
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?>
<i>
:p
But seriously, I don't know PHP very well, Robert Wellock pulled that code off a web-site, pm'ed the code to me and I don't use it. I'm an ASP guy. ;)
[i]Originally posted by samij586 [/i]
[B]the section in blue tells the w3 validator to take the application/xhtml+xml rather than the text/html, I really don't think this has any effect on the validation other than it makes your doctype slightly more strict [/B][/QUOTE]
[code=php]
<?php
if(stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) {
header("content-type: application/xhtml+xml");
}
else {
header("content-type: text/html");
}
?>
[/code]
[i]Originally posted by Paul Jr [/i]Yes, but if you look at the content-type in the validation results, it will say text/html even though you are sending it as application/xhtml+xml. The only reason for doing it, really, is to have the content-type show up as application/xhtml+xml on the W3C's validator.
[B]The validator was fine, and the content type was application/xhtml+xml. [/B][/QUOTE]
0.1.9 — BETA 5.18