Forum Moderators: coopster
Header example:
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
I need to check this against a set of predefined variables:
$variableTwo = "application/xhtml+xml"
$variableTwo = "application/vnd.wap.wml"
$variableThree = "text/plain"
$variableFour = "*/*"
The result needs to tell me what has been matched from the header, and in case of more than one match, which was matched first.
Anyone know how this can be done...
Thans for any help.
Also, sometimes there is a space after the commma, so I also have to make it work when that happens. Any ideas on how to make one array, but make sure all three conditions have been accounted for?
By the way, does anyone know what the q=0.8 and q=0.5 means in the HTTP-headers? I see those pop up in more than the HTTP_ACCEPT-string, but I can't seem to work them out?
$array = array_filter [php.net](explode [php.net](',', preg_replace [php.net]("/;(.*)(,¦$)/Ui", ',', $_SERVER [php.net]['HTTP_ACCEPT'])));
There shouldn't be spaces after the comma in the HTTP_ACCEPT variable, where do you see that? Well, if there were, you would just have to loop through the array and trim() [php.net] the entries.
The qs values refer to the different source qualities as described in the HTTP/1.1 specification [rfc-editor.org]. Apache uses Content Negotiation [httpd.apache.org] to determine the variant precedence.
Don't forget that this forum breaks the pipe symbol (¦) so if you copy and paste the regular expression you will need to rekey the pipe symbol.