PHP code example of neoncitylights / media-type

1. Go to this page and download the library: Download neoncitylights/media-type library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neoncitylights / media-type example snippets




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'



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'



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