PHPackages                             mensbeam/microformats - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. mensbeam/microformats

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

mensbeam/microformats
=====================

A microformats parser

0.2.1(2mo ago)032MITPHPPHP &gt;=7.3

Since Jun 28Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/mensbeam/microformats)[ Packagist](https://packagist.org/packages/mensbeam/microformats)[ RSS](/packages/mensbeam-microformats/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (8)Versions (10)Used By (0)

Microformats
============

[](#microformats)

A generic [Microformats](https://microformats.io/) parser for PHP. While it similar to [php-mf2](https://github.com/microformats/php-mf2), it combines a more accurate HTML parser with more consistent performance characteristics, and it is believed to have fewer bugs.

Usage
-----

[](#usage)

Functionality is provided for parsing from an HTTP URL, from a file, from a string, and from an HTML element (a `\DOMElement` or `\Dom\HTMLElement` object), as well as for serializing to JSON. A static method of the `MensBeam\Microformats` class is provided for each task.

The parsing methods all return a Microformats structure as an array. The [Microformats wiki](https://microformats.org/wiki/microformats2) includes some sample structures in JSON format.

### Parsing from a URL

[](#parsing-from-a-url)

```
\MensBeam\Microformats::fromUrl(string $url, array $options = []): ?array
```

The `$url` argument is an HTTP(S) URL to an HTML resource; redirections will be followed if neceesary. If the resource cannot be fetched `null` will be returned.

The `$options` argument is a list of options for the Microformats parser. See below for details.

### Parsing from a file

[](#parsing-from-a-file)

```
\MensBeam\Microformats::fromFile(string $file, string $contentType, string $url, array $options = []): ?array
```

The `$file` argument is the path to a local file. If the file cannot be opened for reading `null` will be returned.

The `$contentType` argument is a string containing the value of the file's HTTP `Content-Type` header, if known. This may be used to provide the HTML parser with character encoding information.

The `$url` argument is a string containing the file's effective URL. This is used to resolve any relative URLs in the input.

The `$options` argument is a list of options for the Microformats parser. See below for details.

### Parsing from a string

[](#parsing-from-a-string)

```
\MensBeam\Microformats::fromString(string $input, string $contentType, string $url, array $options = []): array
```

The `$input` argument is the string to parse for micrformats.

The `$contentType` argument is a string containing the value of the string's HTTP `Content-Type` header, if known. This may be used to provide the HTML parser with character encoding information.

The `$url` argument is a string containing the string's effective URL. This is used to resolve any relative URLs in the input.

The `$options` argument is a list of options for the Microformats parser. See below for details.

### Parsing from an HTML element

[](#parsing-from-an-html-element)

```
\MensBeam\Microformats::fromHtmlElement(\DOMElement|\Dom\HTMLElement $input, string $url, array $options = []): array
```

The `$input` argument is the element to parse for micrformats. Typically this would be the `documentElement`, but any element may be parsed.

The `$url` argument is a string containing the string's effective URL. This is used to resolve any relative URLs in the input.

The `$options` argument is a list of options for the Microformats parser. See below for details.

### Serializing to JSON

[](#serializing-to-json)

```
\MensBeam\Microformats::toJson(array $data, int $flags = 0, int $depth = 512): string
```

Since Microformats data is represented as a structure of nested arrays, some of which are associative ("objects" in JSON parlance) and may be empty, it is necessary to convert such empty array into PHP `stdClass` objects before they are serialized to JSON. This method performs these conversions before passing the result to [the `json_encode` function](https://www.php.net/manual/en/function.json-encode). Its parameters are the same as that of `json_encode`.

Options
-------

[](#options)

The parsing methods all optionally take an `$options` array as an argument. These options are all flags, either for experimental features, or for backwards-compatible features no longer used by default. The options are as followings:

KeyTypeDefaultDescription`dateNormalization`Boolean`true`This optiona enables date and time normalization throughout microformat parsing rather than only where required by the specification`impliedTz`Boolean`false`Time values in microformats may have an implied date associated with them taken from a prior date value in the same microformat structure. This option allows for a time zone to be implied as well, if a time does not include its time zone.`lang`Boolean`true`This option determines whether language information is retrieved from the parsed document and included in the output, in `lang` keys. Both Microformat structures and embedded markup (`e-` property) structures are affected by this options.`thoroughTrim`Boolean`true`This option uses the more thorough whitespace-trimming algorithm proposed for future standardization rather than the "classic", simpler whitespace-trimming algorithm mandated by the parsing specification. This affects both `p-` and `e-` properties.Change log
----------

[](#change-log)

### Version 0.2.0 (2026-02-17)

[](#version-020-2026-02-17)

- Accept and use `Dom\HTMLDocument` when available (since PHP 8.4)

### Version 0.1.0 (2023-06-28)

[](#version-010-2023-06-28)

- Initial release

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance83

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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 ~126 days

Recently: every ~16 days

Total

9

Last Release

88d ago

PHP version history (2 changes)0.1.0PHP &gt;=7.1

0.1.1PHP &gt;=7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/89590?v=4)[J. King](/maintainers/JKingweb)[@JKingweb](https://github.com/JKingweb)

---

Top Contributors

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

---

Tags

parserhtmlmicroformatsindiewebmf2

### Embed Badge

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

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k269.7M321](/packages/masterminds-html5)[paquettg/php-html-parser

An HTML DOM parser. It allows you to manipulate HTML. Find tags on an HTML page with selectors just like jQuery.

2.5k8.2M130](/packages/paquettg-php-html-parser)[sunra/php-simple-html-dom-parser

Composer adaptation of: A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way! Require PHP 5+. Supports invalid HTML. Find tags on an HTML page with selectors just like jQuery. Extract contents from HTML in a single line.

1.3k9.7M65](/packages/sunra-php-simple-html-dom-parser)[imangazaliev/didom

Simple and fast HTML parser

2.2k2.5M72](/packages/imangazaliev-didom)[mf2/mf2

A pure, generic microformats2 parser — makes HTML as easy to consume as a JSON API

202313.4k45](/packages/mf2-mf2)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1931.4M15](/packages/simplehtmldom-simplehtmldom)

PHPackages © 2026

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