本文整理汇总了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;
}