PHP code example of borschphp / mimetype

1. Go to this page and download the library: Download borschphp/mimetype 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/ */

    

borschphp / mimetype example snippets


use Borsch\MimeType\MimeType;
use Laminas\Diactoros\Request;
use Laminas\Diactoros\Uri;

$mime_type = new MimeType('application', 'json', ['charset' => 'UTF-8']);

$request = (new Request())
    ->withUri(new Uri('http://example.com'))
    ->withMethod('GET')
    ->withAddedHeader('Content-Type', (string)$mime_type);

use Borsch\MimeType\MediaType;
use Laminas\Diactoros\Request;
use Laminas\Diactoros\Uri;

$request = (new Request())
    ->withUri(new Uri('http://example.com'))
    ->withMethod('GET')
    ->withAddedHeader('Content-Type', MediaType::APPLICATION_JSON);

use Borsch\MimeType\MimeType;
use Borsch\MimeType\MediaType;

$mime_type = MimeType::createFromString(
    'application/atom+xml;charset=utf-8;boundary=3d6b6a416f9b5;name=some_file'
);

$mime_type->getType(); // application
$mime_type->getSubtype(); // atom+xml
$mime_type->getSubtypeSuffix() // xml
$mime_type->getCharset(); // utf-8
$mime_type->getParameters(); // ['charset' => 'utf-8', 'boundary' => '3d6b6a416f9b5', 'name' => 'some_file']
$mime_type->getParameter('boundary'); // 3d6b6a416f9b5

$media_type = new MediaType('image', 'png', ['q' => 0.8]);
$media_type->getQualityValue(); // 0.8
$media_type->removeQualityValue();
$media_type->getQualityValue(); // null