Inpsyde\MultilingualPress\Common\AcceptHeader\AcceptHeaderParser::parse PHP Method

parse() public method

Parses the given Accept header and returns the according data in array form.
Since: 3.0.0
public parse ( string $header ) : array
$header string Accept header string.
return array Parsed Accept header in array form.
    public function parse($header);

Usage Example

 /**
  * Inspect HTTP_ACCEPT_LANGUAGE and parse priority parameters.
  *
  * @param string $accept_header Accept header string
  * @return array
  */
 private function parse_accept_header($accept_header)
 {
     $fields = $this->parser->parse($accept_header);
     if (empty($fields)) {
         return $fields;
     }
     $out = [];
     foreach ($fields as $name => $priority) {
         $name = strtolower($name);
         $out[$name] = $priority;
         $short = $this->get_short_form($name);
         if ($short && $short !== $name && !isset($out[$short])) {
             $out[$short] = $priority;
         }
     }
     return $out;
 }
AcceptHeaderParser