protected function sortAccept($header)
    {
        $matches = array();
        foreach (explode(',', $header) as $option) {
            $option = array_map('trim', explode(';', $option));

            $l = strtolower($option[0]);
            if (isset($option[1])) {
                $q = (float) str_replace('q=', '', $option[1]);
            } else {
                $q = null;
                // Assign default low weight for generic values
                if ($l == '*/*') {
                    $q = 0.01;
                } elseif (substr($l, -1) == '*') {
                    $q = 0.02;
                }
            }
            // Unweighted values, get high weight by their position in the
            // list
            $matches[$l] = isset($q) ? $q : 1000 - count($matches);
        }
        arsort($matches, SORT_NUMERIC);
        return $matches;
    }
protected function sortAccept($header)
    {
        $matches = array();
        foreach (explode(',', $header) as $option) {
            $option = array_map('trim', explode(';', $option));

            $l = strtolower($option[0]);
            if (isset($option[1])) {
                $q = (float) str_replace('q=', '', $option[1]);
            } else {
                $q = null;
                // Assign default low weight for generic values
                if ($l == '*/*') {
                    $q = 0.01;
                } elseif (substr($l, -1) == '*') {
                    $q = 0.02;
                }
            }
            // Unweighted values, get high weight by their position in the
            // list
            $matches[$l] = isset($q) ? $q : 1000 - count($matches);
        }
        arsort($matches, SORT_NUMERIC);
        return $matches;
    }
protected function sortAccept ( $ header ) { $ matches = array ( ) ; foreach ( explode ( ',' , $ header ) as $ option ) { $ option = array_map ( 'trim' , explode ( ';' , $ option ) ) ; $ l = strtolower ( $ option [ 0 ] ) ; if ( isset ( $ option [ 1 ] ) ) { $ q = ( float ) str_replace ( 'q=' , '' , $ option [ 1 ] ) ; } else { $ q = null ; // Assign default low weight for generic values if ( $ l == '*/*' ) { $ q = 0.01 ; } elseif ( substr ( $ l , - 1 ) == '*' ) { $ q = 0.02 ; } } // Unweighted values, get high weight by their position in the // list $ matches [ $ l ] = isset ( $ q ) ? $ q : 1000 - count ( $ matches ) ; } arsort ( $ matches , SORT_NUMERIC ) ; return $ matches ; }
Parses and sorts a weighed "Accept" HTTP header

@param string $header The HTTP "Accept" header to parse

@return array Sorted list of "accept" options
Parses and sorts a weighed Accept HTTP header