From b79fa1aac61dcdc40ca1a23f87d85aba0cccec22 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 17 Apr 2020 01:12:56 -0400 Subject: [PATCH] Basic README --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b545d9b --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# MIME Sniffing + +This library aims to be a complete implementation of [the WHATWG Mime Sniffing](https://mimesniff.spec.whatwg.org/) 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: + +```php +$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: + +```php +$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" +```