You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
J. King
cce75a26cb
|
4 years ago | |
---|---|---|
lib | 4 years ago | |
tests | 4 years ago | |
vendor-bin | 4 years ago | |
.gitattributes | 4 years ago | |
.gitignore | 4 years ago | |
.php_cs.dist | 4 years ago | |
AUTHORS | 4 years ago | |
CHANGELOG | 4 years ago | |
LICENSE | 4 years ago | |
README.md | 4 years ago | |
RoboFile.php | 4 years ago | |
composer.json | 4 years ago | |
composer.lock | 4 years ago | |
robo | 4 years ago | |
robo.bat | 4 years ago |
README.md
MIME Sniffing
This library aims to be a complete implementation of the WHATWG Mime Sniffing specification. Presently it only implements MIME type parsing (in other words, MIME sniffing itself is not implemented), but it will be expanded in due course.
Features
Parsing
A MIME type string may be parsed into a structured MimeType
instance as follows:
$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"
Normalizing
Once parsed, a MimeType
instance can be serialized to produce a normalized text representation:
$typeString = 'TeXt/HTML; CHARset="UTF\-8"; charset=iso-8859-1; unset=';
$mimeType = \MensBeam\Mime\MimeType::parse($typeString);
echo (string) $mimeType; // prints "text/html;charset=UTF-8"