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)25422[1 PRs](https://github.com/mensbeam/mime/pulls)2MITPHPPHP &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 2d ago

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

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 69% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity46

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

522d ago

PHP version history (2 changes)0.1.0PHP ^7.1

0.2.1PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/89590?v=4)[J. King](/maintainers/JKingweb)[@JKingweb](https://github.com/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

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[symfony/symfony

The Symfony PHP framework

31.4k87.4M2.2k](/packages/symfony-symfony)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B4.4k](/packages/guzzlehttp-psr7)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k832.6k52](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k19](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

36826.2k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

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