本文整理匯總了PHP中Arrays::trimExplode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Arrays::trimExplode方法的具體用法?PHP Arrays::trimExplode怎麽用?PHP Arrays::trimExplode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Arrays
的用法示例。
在下文中一共展示了Arrays::trimExplode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parseMediaType
/**
* Parses a RFC 2616 Media Type and returns its parts in an associative array.
*
* media-type = type "/" subtype *( ";" parameter)
*
* The media type "text/html; charset=UTF-8" would be parsed and returned with
* the following array keys and values:
*
* "type" => the type as a string, "text"
* "subtype" => the subtype as a string, "html"
* "parameters" => an array of parameter names and values, array("charset" => "UTF-8")
*
* @param string $rawMediaType The raw media type, for example "application/json; charset=UTF-8"
* @return array An associative array with parsed information
*/
public static function parseMediaType($rawMediaType)
{
preg_match(self::PATTERN_SPLITMEDIATYPE, $rawMediaType, $matches);
$result = [];
$result['type'] = isset($matches['type']) ? $matches['type'] : '';
$result['subtype'] = isset($matches['subtype']) ? $matches['subtype'] : '';
$result['parameters'] = [];
if (isset($matches['parameters'])) {
foreach (Arrays::trimExplode(';', $matches['parameters']) as $parameter) {
$pieces = explode('=', $parameter);
if (count($pieces) === 2) {
$name = trim($pieces[0]);
$result['parameters'][$name] = trim($pieces[1]);
}
}
}
return $result;
}