text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
CCBot/2.0 (https://commoncrawl.org/faq/)
array(4) {
  [0]=>
  string(9) "text/html"
  [1]=>
  string(21) "application/xhtml+xml"
  [2]=>
  string(21) "application/xml;q=0.9"
  [3]=>
  string(9) "*/*;q=0.8"
}

text/html: 1
application/xhtml+xml: 1
I'll serve you application/xhtml+xml
<?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 ); //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 ); //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__);
?>