*/*
Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
array(1) {
[0]=>
string(3) "*/*"
}
text/html: 0
application/xhtml+xml: 0
I'll serve you text/html
<?php
echo '<pre>';
echo $_SERVER["HTTP_ACCEPT"];
echo "\n".$_SERVER["HTTP_USER_AGENT"]."\n";
$accept_header = explode( ',', $_SERVER["HTTP_ACCEPT"]);
var_dump($accept_header);
$xhtml_value = preg_grep( '/application\/xhtml\+xml(;q=(0\.\d{1,5}|1\.0|[01]))?$/i', $accept_header);
$xhtml_value = array_values($xhtml_value); //reset the keys
if (count($xhtml_value) == 0)
{
$xhtmlxml = floatval(0.0); //if you're not specified anywhere, you dont' support it
}
else
{
//now parse the XHTML value found for any q-value
if ( strpos($xhtml_value[0], 'q') === FALSE )
{
//with no q-value explicitly set, then your XHTML support is 1
$xhtmlxml = floatval(1.0);
}
else
{
//with one specified, lets obtain it
$qloc = strpos($xhtml_value[0], 'q');
$qvalue = substr($xhtml_value[0], $qloc + 2 ); //we add two to skip past the = sign
$xhtmlxml = floatval($qvalue);
}
}
//now do the above but for text/html
$html_value = preg_grep( '/text\/html(;q=(0\.\d{1,5}|1\.0|[01]))?$/i', $accept_header);
$html_value = array_values($html_value); //reset the keys
if (count($html_value) == 0)
{
$texthtml = floatval(0.0); //if you're not specified anywhere, you dont' support it
}
else
{
//now parse the HTML value found for any q-value
if ( strpos($html_value[0], 'q') === FALSE )
{
//with no q-value explicitly set, then your HTML support is 1
$texthtml = floatval(1.0);
}
else
{
//with one specified, lets obtain it
$qloc = strpos($html_value[0], 'q');
$qvalue = substr($html_value[0], $qloc + 2 ); //we add two to skip past the = sign
$texthtml = floatval($qvalue);
}
}
echo "\ntext/html: " . $texthtml;
echo "\napplication/xhtml+xml: " .$xhtmlxml;
//now a bit of test processing.
/*ok, here we have three options:
1: $xhtmlxml > $texthtml == serve application/xhtml+xml
2: $xhtmlxml == $texthtml == serve application/xhtml+xml
3: $xhtmlxml < $texthtml == serve text/html
*/
if ($xhtmlxml > $texthtml || ($xhtmlxml == $texthtml && $texthtml > 0))
{
echo "\nI'll serve you application/xhtml+xml\n";
}
else
{
echo "\nI'll serve you text/html\n";
}
echo '</pre>';
highlight_file(__FILE__);
?>