MediaType is a PHP library for parsing and serializing MIME types, also known as IANA media types.
This library is compliant to the WHATWG Mime Sniffing Standard.
System requirements:
- Minimum PHP version: 8.2
intl
PHP extension (installation instructions)
composer require neoncitylights/media-type
<?php
use Neoncitylights\MediaType\MediaType;
use Neoncitylights\MediaType\MediaTypeParser;
$parser = new MediaTypeParser();
$mediaType = $parser->parseOrNull( 'text/plain;charset=UTF-8' );
print( $mediaType->type ); // 'text'
print( $mediaType->subType ); // 'plain'
print( $mediaType->getEssence() ); // 'text/plain'
print( $mediaType->getParameterValue( 'charset' ) ); // 'UTF-8'
<?php
use Neoncitylights\MediaType\MediaType;
$mediaType1 = new MediaType( 'text', 'plain', [ 'charset' => 'UT-8' ] );
$mediaType1->toString(); // 'text/plain;charset=UTF-8'
$mediaType2 = new MediaType( 'application', 'json', [] );
$mediaType2->toString(); // 'application/json'
<?php
use Neoncitylights\MediaType\MediaType;
use Neoncitylights\MediaType\MediaTypeParser;
$parser = new MediaTypeParser();
$parser->parseOrNull( 'audio/midi' )->isAudioOrVideo(); // true
$parser->parseOrNull( 'audio/ogg' )->isAudioOrVideo(); // true
$parser->parseOrNull( 'application/ogg' )->isAudioOrVideo(); // true
This software is licensed under the MIT license (LICENSE-MIT
or https://opensource.org/license/mit/).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.