本文整理汇总了PHP中request::accept_types方法的典型用法代码示例。如果您正苦于以下问题:PHP request::accept_types方法的具体用法?PHP request::accept_types怎么用?PHP request::accept_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request
的用法示例。
在下文中一共展示了request::accept_types方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset
public static function reset()
{
request::$accept_charsets = NULL;
request::$accept_encodings = NULL;
request::$accept_languages = NULL;
request::$accept_types = NULL;
request::$user_agent = NULL;
}
示例2: parse_accept_header
/**
* Parses client's HTTP Accept request header, and builds array structure representing it.
*
* @return void
*/
protected static function parse_accept_header()
{
// Run this function just once
if (request::$accept_types !== NULL) {
return;
}
// Initialize accept_types array
request::$accept_types = array();
// No HTTP Accept header found
if (empty($_SERVER['HTTP_ACCEPT'])) {
// Accept everything
request::$accept_types['*']['*'] = 1;
return;
}
// Remove linebreaks and parse the HTTP Accept header
foreach (explode(',', str_replace(array("\r", "\n"), '', $_SERVER['HTTP_ACCEPT'])) as $accept_entry) {
// Explode each entry in content type and possible quality factor
$accept_entry = explode(';', trim($accept_entry), 2);
// Explode each content type (e.g. "text/html")
$type = explode('/', $accept_entry[0], 2);
// Skip invalid content types
if (!isset($type[1])) {
continue;
}
// Assume a default quality factor of 1 if no custom q value found
$q = (isset($accept_entry[1]) and preg_match('~\\bq\\s*+=\\s*+([.0-9]+)~', $accept_entry[1], $match)) ? (double) $match[1] : 1;
// Populate accept_types array
if (!isset(request::$accept_types[$type[0]][$type[1]]) or $q > request::$accept_types[$type[0]][$type[1]]) {
request::$accept_types[$type[0]][$type[1]] = $q;
}
}
}
示例3: parse_accept_content_header
/**
* Parses a client's HTTP Accept header
*/
protected static function parse_accept_content_header()
{
// Run this function just once
if (request::$accept_types !== NULL) {
return;
}
// No HTTP Accept header found
if (empty($_SERVER['HTTP_ACCEPT'])) {
// Accept everything
request::$accept_types['*']['*'] = 1;
} else {
request::$accept_types = array();
foreach (request::parse_accept_header($_SERVER['HTTP_ACCEPT']) as $type => $q) {
// Explode each content type (e.g. "text/html")
$type = explode('/', $type, 2);
// Skip invalid content types
if (!isset($type[1])) {
continue;
}
request::$accept_types[$type[0]][$type[1]] = $q;
}
}
}