1. Go to this page and download the library: Download mensbeam/mimesniff 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/ */
mensbeam / mimesniff example snippets
$mimeType = \MensBeam\Mime\MimeType::parse("text/HTML; charSet=UTF-8");
echo $mimeType->type; // prints "text"
echo $mimeType->subtype; // prints "html"
echo $mimeType->essence; // prints "text/html"
echo $mimeType->params['charset']; // prints "UTF-8"
/* Assume $response is a PSR-7 HTTP message containing the following
header fields:
Content-Type: text/html; charset=UTF-8, invalid
Content-Type:
Content-Type: text/html; foo=bar
*/
echo (string) \MensBeam\Mime\MimeType::extract($response->getHeader("Content-Type")); // prints "text/html;foo=bar;charset=UTF-8"
echo (string) \MensBeam\Mime\MimeType::extract($response->getHeaderLine("Content-Type")); // also prints "text/html;foo=bar;charset=UTF-8"
/* Assume $request1 is a PSR-7 HTTP message containing the following
header fields:
Accept: application/json;q=0.8, application/xml
Accept: text/html;q=0.1, text/*;q=0.7
Assume $request2 is a PSR-7 HTTP message containing the following
header fields:
Accept: application/xml
Accept: application/json
*/
$ourTypes1 = ["application/json", "application/xml"];
$ourTypes2 = ["text/html", "text/xml", "text/plain"];
echo \MensBeam\Mime\MimeType::negotiate($ourTypes1, $request1->getHeader("Accept")); // "application/xml" has higher qvalue, so is returned
echo \MensBeam\Mime\MimeType::negotiate($ourTypes2, $request1->getHeaderLine("Accept")); // "text/html" has lower qvalue and is disqualified; "text/xml" appears first in our array, so is returned
echo \MensBeam\Mime\MimeType::negotiate($ourTypes1, $request2->getHeader("Accept")); // "application/json" appears first in our array, so is returned
echo \MensBeam\Mime\MimeType::negotiate($ourTypes2, $request2->getHeaderLine("Accept")); // no types are acceptable; null is returned
$mimeType = \MensBeam\Mime\MimeType::parse("image/svg+xml");
var_export($mimeType->isImage); // prints "true"
var_export($mimeType->isXml); // prints "true"
var_export($mimeType->isScriptable); // prints "true"
var_export($mimeType->isArchive); // prints "false"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.