Mimeparse
class Mimeparse
Mimeparser class. This class provides basic functions for handling mime-types. It can handle matching mime-types against a list of media-ranges. See section 14.1 of the HTTP specification [RFC 2616] for a complete explanation.
It's just a port to php from original Python code (http://code.google.com/p/mimeparse/)
Methods
Carves up a mime-type and returns an Array of the [type, subtype, params] where "params" is a Hash of all the parameters for the media range.
Carves up a media range and returns an Array of the [type, subtype, params] where "params" is a Hash of all the parameters for the media range.
Find the best match for a given mime-type against a list of media_ranges that have already been parsed by Mimeparser::parse_media_range()
Find the best match for a given mime-type against a list of media_ranges that have already been parsed by Mimeparser::parse_media_range()
Returns the quality "q" of a mime-type when compared against the media-ranges in ranges. For example:
Takes a list of supported mime-types and finds the best match for all the media-ranges listed in header. The value of header must be a string that conforms to the format of the HTTP Accept: header. The value of supported is an Enumerable of mime-types
Details
at line 41
array
parse_mime_type(string $mime_type)
Carves up a mime-type and returns an Array of the [type, subtype, params] where "params" is a Hash of all the parameters for the media range.
For example, the media range "application/xhtml;q=0.5" would get parsed into:
array("application", "xhtml", array( "q" => "0.5" ))
at line 90
array
parse_media_range(string $range)
Carves up a media range and returns an Array of the [type, subtype, params] where "params" is a Hash of all the parameters for the media range.
For example, the media range "application/*;q=0.5" would get parsed into:
array("application", "*", ( "q", "0.5" ))
In addition this function also guarantees that there is a value for "q" in the params dictionary, filling it in with a proper default if necessary.
at line 112
array
fitness_and_quality_parsed(string $mime_type, array $parsed_ranges)
Find the best match for a given mime-type against a list of media_ranges that have already been parsed by Mimeparser::parse_media_range()
Returns the fitness and the "q" quality parameter of the best match, or an array [-1, 0] if no match was found. Just as for Mimeparser::quality(), "parsed_ranges" must be an Enumerable of parsed media ranges.
at line 155
float
quality_parsed(string $mime_type, array $parsed_ranges)
Find the best match for a given mime-type against a list of media_ranges that have already been parsed by Mimeparser::parse_media_range()
Returns the "q" quality parameter of the best match, 0 if no match was found. This function behaves the same as Mimeparser::quality() except that "parsed_ranges" must be an Enumerable of parsed media ranges.
at line 172
unknown
quality(unknown_type $mime_type, unknown_type $ranges)
Returns the quality "q" of a mime-type when compared against the media-ranges in ranges. For example:
Mimeparser::quality("text/html", "text/;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, *\/;q=0.5") => 0.7
at line 194
mixed
best_match(array $supported, string $header)
Takes a list of supported mime-types and finds the best match for all the media-ranges listed in header. The value of header must be a string that conforms to the format of the HTTP Accept: header. The value of supported is an Enumerable of mime-types
Mimeparser::best_match(array("application/xbel+xml", "text/xml"), "text/;q=0.5,\/*; q=0.1") => "text/xml"