PHPackages                             rickselby/nbt - 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. rickselby/nbt

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

rickselby/nbt
=============

Parser/Writer for the NBT file format

4.1.0(2y ago)171.2k↓50%6[1 issues](https://github.com/rickselby/NBT/issues)[2 PRs](https://github.com/rickselby/NBT/pulls)1MITPHPPHP &gt;=8.1.0CI failing

Since Jun 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rickselby/NBT)[ Packagist](https://packagist.org/packages/rickselby/nbt)[ Docs](https://github.com/rickselby/NBT)[ RSS](/packages/rickselby-nbt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (17)Used By (1)

This is a Named Binary Tag parser based upon the specification by Markus Persson.

From the spec: "NBT (Named Binary Tag) is a tag based binary format designed to carry large amounts of binary data with smaller amounts of additional data. An NBT file consists of a single GZIPped Named Tag of type TAG\_Compound."

NBT data is also used in region files, which store the data for Minecraft worlds.

**Requires the GMP Extension for PHP on 32-bit builds.**

Installing
----------

[](#installing)

### Composer

[](#composer)

The library can be pulled in using composer; add the following to your composer.json:

```
{
    "require": {
        "rickselby/nbt": "~4.0"
    }
}

```

Usage
-----

[](#usage)

Reading in from files, resources, or strings:

```
$nbtService = new \Nbt\Service(new \Nbt\DataHandler());
$tree = $nbtService->loadFile('filename.nbt');
$tree = $nbtService->readFilePointer($fPtr);
$tree = $nbtService->readString($nbtString);
```

Then writing to a file, a resource, or returning a string:

```
$nbtService->writeFile('filename.nbt', $tree);
$nbtService->writeFilePointer($fPtr, $tree);
$nbtString = $nbtService->writeString($tree);
```

To look through a tree:

```
echo $tree->getName();
$type = $tree->getType();

// Value isn't set for Lists and Compounds; those nodes have children instead
$value = $tree->getValue();

$sectionsNode = $tree->findChildByName('Sections');
```

To update a tree:

```
$node->setName('Name');
$node->setValue(123456);
```

To create new nodes:

```
// This is pretty useless on it's own really
$node = \Nbt\Tag::tagByte('aByte', 0x0f);

// You'll be building trees with Compounds and Lists mostly; both take an array of nodes as their values
$tree = \Nbt\Tag::tagCompound('aCompound', [
    \Nbt\Tag::tagByte('aByte', 0x0f),
    \Nbt\Tag::tagInt('aNumber', 12345),
]);

// Child tags for lists do not require names, as they are not named - and they must match the payload of the list
$tree = \Nbt\Tag::tagList('aList', \Nbt\Tag::TAG_STRING, [
    \Nbt\Tag::tagString('', 'firstString'),
    \Nbt\Tag::tagString('', 'secondString'),
]);
```

History
-------

[](#history)

The original PHP NBT package was written by [TheFrozenFire](//github.com/TheFrozenFire/PHP-NBT-Decoder-Encoder).

This repo has been forked by many, but most forks have one of two issues; they either don't handle TAG\_INT\_ARRAY or don't correctly handle writing to a file pointer.

The returned format - an array - isn't ideal for creating your own NBT data, and some kind of wrapper was required to assist in creation.

I tidied up the code a little, then added nicmart/tree to store the NBT data; after much work, it's nothing like the original, so I've pulled it into it's own (non-forked) repo.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 69.7% 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 ~293 days

Recently: every ~744 days

Total

14

Last Release

897d ago

Major Versions

1.0.3 → 2.0.02015-10-06

2.0.0 → 3.0.02015-10-08

3.1.1 → 4.0.02015-12-16

PHP version history (3 changes)1.0.0PHP &gt;=5.3.0

3.0.0PHP &gt;=5.4.0

4.1.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cc8910980f053d8ceb2e9d938427cf03ae509884763a10f916b4eef5591934f?d=identicon)[rickselby](/maintainers/rickselby)

---

Top Contributors

[![rickselby](https://avatars.githubusercontent.com/u/1564517?v=4)](https://github.com/rickselby "rickselby (101 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (20 commits)")[![TheFrozenFire](https://avatars.githubusercontent.com/u/948014?v=4)](https://github.com/TheFrozenFire "TheFrozenFire (18 commits)")[![sumpygump](https://avatars.githubusercontent.com/u/676007?v=4)](https://github.com/sumpygump "sumpygump (4 commits)")[![Hunman](https://avatars.githubusercontent.com/u/7405480?v=4)](https://github.com/Hunman "Hunman (1 commits)")[![xPaw](https://avatars.githubusercontent.com/u/613331?v=4)](https://github.com/xPaw "xPaw (1 commits)")

---

Tags

minecraftnbtphpencodedecodebinaryNBT

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rickselby-nbt/health.svg)

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

###  Alternatives

[yethee/tiktoken

PHP version of tiktoken

1583.1M15](/packages/yethee-tiktoken)[gioni06/gpt3-tokenizer

PHP package for Byte Pair Encoding (BPE) used by GPT-3.

85537.5k8](/packages/gioni06-gpt3-tokenizer)[kherge/json

Encodes, decodes, and validates JSON data.

61226.6k6](/packages/kherge-json)[devium/toml

A PHP encoder/decoder for TOML compatible with specification 1.0.0

3968.9k13](/packages/devium-toml)

PHPackages © 2026

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