Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Content Negotiation (See related posts)

Serve XHTML as application/xhtml+xml to browsers which accept it (and to W3C Validator).

<?php 
header("Vary: Accept");
if (stristr($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') || stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))
{
  header('Content-type: application/xhtml+xml');
  echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}
else
{
  header('Content-type: text/html');
}
?>

Comments on this post

d2s posts on Aug 08, 2005 at 20:41
Thanks much for code. This is just what I was looking for.
d2s posts on Aug 19, 2005 at 12:40
I think that it should send character encoding with text/html header.

  header('Content-Type: text/html; charset=UTF-8');

You need to create an account or log in to post comments to this site.


Click here to browse all 5141 code snippets

Related Posts