Es kann aber auch sein, dass der Browser ausdrücklich angibt, dass text/html gegenüber application/xhtml+xml bevorzugt wird. Wenn man das berücksichtigen will, geht das so:
$xhtml = false;
if (preg_match('/application\/xhtml\+xml(;q=(\d+\.\d+))?/i', $_SERVER['HTTP_ACCEPT'], $matches))
{
$xhtmlQ = isset($matches[2]) ? $matches[2] : 1;
if (preg_match('/text\/html(;q=(\d+\.\d+))?/i', $_SERVER['HTTP_ACCEPT'], $matches))
{
$htmlQ = isset($matches[2]) ? $matches[2] : 1;
$xhtml = ($xhtmlQ >= $htmlQ);
}
else $xhtml = true;
}
if($xhtml) { header('content-type: application/xhtml+xml; charset=utf-8'); }
else { header('content-type: text/html; charset=utf-8'); }