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

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

gekkone/nbt
===========

Parser/Writer for the NBT file format

4.1.0(4y ago)08MITPHPPHP &gt;=5.4.0

Since Jun 26Pushed 4y agoCompare

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

READMEChangelogDependencies (3)Versions (15)Used By (0)

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": {
        "gekkone/nbt": "~4.1"
    }
}

```

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

28

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 71.8% 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 ~233 days

Recently: every ~547 days

Total

14

Last Release

1764d 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 (2 changes)1.0.0PHP &gt;=5.3.0

3.0.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/764476c8716456da9ec0242f15c423ca0528a17e0950a07abc44551f6c3a85f0?d=identicon)[gekkone](/maintainers/gekkone)

---

Top Contributors

[![rickselby](https://avatars.githubusercontent.com/u/1564517?v=4)](https://github.com/rickselby "rickselby (61 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

encodedecodebinaryNBT

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[yethee/tiktoken

PHP version of tiktoken

1664.3M33](/packages/yethee-tiktoken)[rickselby/nbt

Parser/Writer for the NBT file format

171.3k1](/packages/rickselby-nbt)[gioni06/gpt3-tokenizer

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

84607.8k14](/packages/gioni06-gpt3-tokenizer)[kherge/json

Encodes, decodes, and validates JSON data.

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

A PHP encoder/decoder for TOML compatible with 1.0.0 and 1.1.0

4087.5k28](/packages/devium-toml)[serafim/json5

JSON5 parser

231.2k](/packages/serafim-json5)

PHPackages © 2026

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