PHP code example of dflydev / apache-mime-types

1. Go to this page and download the library: Download dflydev/apache-mime-types 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/ */

    

dflydev / apache-mime-types example snippets



$parser = new Dflydev\ApacheMimeTypes\Parser;

$map = $parser->parse('/path/to/mime.types');


array(
    'text/html' => array('html', 'htm'),
);


$repository = new Dflydev\ApacheMimeTypes\PhpRepository;

$type = $repository->findType('html');
$extensions = $repository->findExtensions('text/html');

var_dump($type);
var_dump($extensions);

//
// Result
//
// string(9) "text/html"
// array(2) {
//   [0]=>
//   string(4) "html"
//   [1]=>
//   string(3) "htm"
// }
//


$repository = new Dflydev\ApacheMimeTypes\JsonRepository;

$type = $repository->findType('html');
$extensions = $repository->findExtensions('text/html');

var_dump($type);
var_dump($extensions);

//
// Result
//
// string(9) "text/html"
// array(2) {
//   [0]=>
//   string(4) "html"
//   [1]=>
//   string(3) "htm"
// }
//


$repository = new Dflydev\ApacheMimeTypes\JsonRepository('/path/to/mime.types.json');


$repository = new Dflydev\ApacheMimeTypes\FlatRepository;

$type = $repository->findType('html');
$extensions = $repository->findExtensions('text/html');

var_dump($type);
var_dump($extensions);

//
// Result
//
// string(9) "text/html"
// array(2) {
//   [0]=>
//   string(4) "html"
//   [1]=>
//   string(3) "htm"
// }
//


$repository = new Dflydev\ApacheMimeTypes\FlatRepository('/path/to/mime.types');