Oihana PHP

normalizeMimeType.php

Table of Contents

Functions

normalizeMimeType()  : string
Brings a MIME type name back to the reference name of its format.

Functions

normalizeMimeType()

Brings a MIME type name back to the reference name of its format.

normalizeMimeType(string $mimeType) : string

The name is lower-cased, its parameters are dropped (audio/wav; codecs=1 gives audio/wav), and an alias listed in MimeTypeAlias::ALIASES becomes the name the catalogue uses (audio/x-wav gives audio/wav). A name the table does not list comes back lower-cased and without parameters, unchanged otherwise.

Two names of the same format then compare equal, whichever one finfo reports on a given host and whichever one a caller wrote : FileMimeType::getExtension() and validateMimeType() compare normalized names.

Parameters
$mimeType : string

The MIME type name, as reported by finfo or declared by a client.

Tags
author

Marc Alcaraz (ekameleon)

since
1.4.0
example
use function oihana\files\normalizeMimeType;

normalizeMimeType( 'audio/x-wav'               ) ; // 'audio/wav'
normalizeMimeType( 'Text/XML; charset=utf-8'   ) ; // 'application/xml'
normalizeMimeType( 'image/png'                 ) ; // 'image/png'
normalizeMimeType( 'application/x-unknown'     ) ; // 'application/x-unknown'
Return values
string —

The reference name of the format, or the cleaned name when it has no alias.

On this page

Search results