public function Mimeparse::parse_mime_type in Services 6.3
Same name and namespace in other branches
- 7.3 servers/rest_server/lib/mimeparse.php \Mimeparse::parse_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" ))
Parameters
string $mime_type:
Return value
array ($type, $subtype, $params)
1 call to Mimeparse::parse_mime_type()
- Mimeparse::parse_media_range in servers/
rest_server/ lib/ mimeparse.php - 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.
File
- servers/
rest_server/ lib/ mimeparse.php, line 15
Class
Code
public function parse_mime_type($mime_type) {
$parts = explode(";", $mime_type);
$params = array();
foreach ($parts as $i => $param) {
if (strpos($param, '=') !== false) {
list($k, $v) = explode('=', trim($param));
$params[$k] = $v;
}
}
$full_type = trim($parts[0]);
/* Java URLConnection class sends an Accept header that includes a single "*"
Turn it into a legal wildcard. */
if ($full_type == '*') {
$full_type = '*/*';
}
list($type, $subtype) = explode('/', $full_type);
if (!$subtype) {
throw new Exception("malformed mime type");
}
return array(
trim($type),
trim($subtype),
$params,
);
}