DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Content Negotiation

04.21.2005
| 2666 views |
  • submit to reddit
        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

Snippets Manager replied on Mon, 2012/05/07 - 1:12pm

I think that it should send character encoding with text/html header. header('Content-Type: text/html; charset=UTF-8');

Snippets Manager replied on Mon, 2012/05/07 - 1:12pm

Thanks much for code. This is just what I was looking for.