PHPackages                             mensbeam/mimesniff - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. mensbeam/mimesniff

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

mensbeam/mimesniff
==================

An implementation of the WHATWG MIME Sniffing specification

0.3.0(1y ago)2289↓100%2[1 PRs](https://github.com/mensbeam/mime/pulls)1MITPHPPHP &gt;=7.1

Since Apr 17Pushed 1y ago2 watchersCompare

[ Source](https://github.com/mensbeam/mime)[ Packagist](https://packagist.org/packages/mensbeam/mimesniff)[ RSS](/packages/mensbeam-mimesniff/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (7)Used By (1)

MIME Sniffing
=============

[](#mime-sniffing)

This library aims to be a complete implementation of [the WHATWG Mime Sniffing](https://mimesniff.spec.whatwg.org/) specification, along with other features related to MIME types. Presently it does not implement MIME sniffing itself, but it will be expanded in due course once the specification stabilizes.

Features
--------

[](#features)

### Parsing

[](#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

[](#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"
```

### Extracting from HTTP headers

[](#extracting-from-http-headers)

A structured `MimeType` instance may also be produced [from one or more HTTP header lines](https://fetch.spec.whatwg.org/#concept-header-extract-mime-type) using the `extract()` method:

```
/* 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"
```

### Negotiating a content type

[](#negotiating-a-content-type)

[HTTP content type negotiation](https://www.rfc-editor.org/rfc/rfc9110.html#name-accept) can be performed using the `negotiate` static method:

```
/* 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
```

### MIME type groups

[](#mime-type-groups)

The MIME Sniffing specification defines a series of [MIME type groups](https://mimesniff.spec.whatwg.org/#mime-type-groups); these are exposed via the boolean properties `isArchive`, `isAudioVideo`, `isFont`, `isHtml`, `isImage`, `isJavascript`, `isJson`, `isScriptable`, `isXml`, and `isZipBased`. For example:

```
$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"
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance45

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~446 days

Total

5

Last Release

429d ago

PHP version history (2 changes)0.1.0PHP ^7.1

0.2.1PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/c92ee740b64f961a67127263de9c7ac85b4b934fc7d0e6a397ed8b16a7f09f91?d=identicon)[JKingweb](/maintainers/JKingweb)

![](https://www.gravatar.com/avatar/fa45644fa8847647e3d12802571072bbd4f3da8d27ed03f6f8df3c3859db6f6e?d=identicon)[dustinwilson](/maintainers/dustinwilson)

---

Top Contributors

[![JKingweb](https://avatars.githubusercontent.com/u/89590?v=4)](https://github.com/JKingweb "JKingweb (32 commits)")

---

Tags

mimemime-typesparsermimeWHATWGmimesniff

### Embed Badge

![Health badge](/badges/mensbeam-mimesniff/health.svg)

```
[![Health](https://phpackages.com/badges/mensbeam-mimesniff/health.svg)](https://phpackages.com/packages/mensbeam-mimesniff)
```

###  Alternatives

[symfony/mime

Allows manipulating MIME messages

2.8k668.8M909](/packages/symfony-mime)[zbateson/mail-mime-parser

MIME email message parser

53949.2M79](/packages/zbateson-mail-mime-parser)[php-mime-mail-parser/php-mime-mail-parser

A fully tested email parser for PHP 8.0+ (mailparse extension wrapper).

9979.6M27](/packages/php-mime-mail-parser-php-mime-mail-parser)[nette/mail

📧 Nette Mail: A handy library for creating and sending emails in PHP.

5389.8M246](/packages/nette-mail)[zbateson/stream-decorators

PHP psr7 stream decorators for mime message part streams

4748.6M6](/packages/zbateson-stream-decorators)[dflydev/apache-mime-types

Apache MIME Types

701.9M35](/packages/dflydev-apache-mime-types)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
