I've used the SplPriorityQueue to determine an HTTP client's preferred MIME types.
<?php
$queue = new \SplPriorityQueue();
foreach (preg_split('#,\s*#', $_SERVER['HTTP_ACCEPT']) as $accept) {
$split = preg_split('#;\s*q=#', $accept, 2);
$queue->insert($split[0], isset($split[1]) ? (float)$split[1] : 1.0);
}
foreach ($queue as $mime) {
echo $mime, PHP_EOL;
}
?>
My browser sends:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
And this script outputs:
text/html
application/xhtml+xml
application/xml
*/*
A better example:
Accept: text/html, application/xml,text/css;q=0.4,text/plain; q=0.9, application/json;q=0.8
And this script outputs:
text/html
application/xml
text/plain
application/json
text/css