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

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

brandon/nbt
===========

A NBT parser that parses to native PHP types

v1.0.0(5y ago)83132MITPHPPHP &gt;=5.3.0

Since Oct 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/BrandonXLF/NBT.php)[ Packagist](https://packagist.org/packages/brandon/nbt)[ RSS](/packages/brandon-nbt/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

NBT to PHP
==========

[](#nbt-to-php)

NBT to PHP allows you to convert NBT data to PHP data types to easily use within a PHP program.

Introduction
------------

[](#introduction)

Since this program converts the NBT data to native PHP data types, there is currently no way to convert the data back to NBT data since PHP has fewer data types than NBT.

An advantage is having no PHP to NBT converter is this library is very lightweight and works very well in applications where read-only functionality is needed, like reading from an API or file.

An advantage of the approach of converting to PHP data types is that it is very easy to display and read the output using [`print_r`](https://www.php.net/manual/en/function.print-r.php).

Installation
------------

[](#installation)

Composer
--------

[](#composer)

This library can be downloaded using [Composer](https://getcomposer.org/). For example you can add the following to your `composer.json` file.

```
{
    "require": {
        "brandon/nbt": "*"
    }
}
```

It is recommended to replace `*` with a version constraint.

Git
---

[](#git)

There are several ways to download directly from GitHub, the only required file is `NBT.php`.

- Download `NBT.php` via
- Clone repository using `git clone https://github.com/BrandonXLF/NBT.php`
- Download code from GitHub

After downloading, to use the library you would use:

```
require 'NBT.php';
```

Documentation
-------------

[](#documentation)

As of now, all functions in this library as static, meaning there's no need to create a new object of type NBT, but you can.

There are 3 main functions that you should access, `NBT::readFile`, `NBT::readString`, and `NBT::readStream`.

### NBT::readFile

[](#nbtreadfile)

NBT::readFile is used to read NBT data from a file.

```
NBT::readFile( string $filename, string $wrapper = 'compress.zlib://' ) : array
```

#### Parameters

[](#parameters)

- **$filename** - The name of the file to read from
- **$wrapper** - The wrapper to use to read the file, by default it is `compress.zlib://`. Change the wrapper to `file://` to read a uncompressed file.

#### Returns

[](#returns)

An array with the NBT data converted to PHP.

### NBT::readString

[](#nbtreadstring)

NBT::readString is used to read NBT data from a string.

```
NBT::readString( string $str ) : array
```

#### Parameters

[](#parameters-1)

- **$str** - The string to binary uncompressed NBT data. If you need to read compressed data, you'll likely need to use [`gzdecode`](https://www.php.net/manual/en/function.gzdecode) to decompress the string first.

#### Returns

[](#returns-1)

An array with the NBT data converted to PHP.

### NBT::readStream

[](#nbtreadstream)

NBT::readStream is used to read NBT data from a file stream.

```
NBT::readStream( resource $stream ) : array
```

#### Parameters

[](#parameters-2)

- **$str** - A binary file stream to read the NBT data from.

#### Returns

[](#returns-2)

An array with the NBT data converted to PHP.

### NBT::readTag

[](#nbtreadtag)

NBT::readTag is used to read a NBT tag from a file stream.

```
NBT::readTag( int $type, resource $stream ) : mixed
```

#### Parameters

[](#parameters-3)

- **$type** - The ID of the type of NBT tag. It is recommended to use one of the constants defined at the top of NBT.php.
- **$stream** - The file stream to read from.

#### Returns

[](#returns-3)

The NBT data read as PHP data, return type depends on the `$type` parameter.

Testing
-------

[](#testing)

Tests for this script can be found in the `tests/test.php` php file. You may run `php tests/test.php` to test this script.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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

Unknown

Total

1

Last Release

2034d ago

### Community

Maintainers

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

---

Top Contributors

[![BrandonXLF](https://avatars.githubusercontent.com/u/42590338?v=4)](https://github.com/BrandonXLF "BrandonXLF (7 commits)")[![kant](https://avatars.githubusercontent.com/u/32717?v=4)](https://github.com/kant "kant (1 commits)")

---

Tags

minecraftnbtnbt-librarynbt-parserphpphp-librarydecodeparsebinaryNBTminecraft

### Embed Badge

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

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

###  Alternatives

[yethee/tiktoken

PHP version of tiktoken

1583.1M15](/packages/yethee-tiktoken)[aranyasen/hl7

HL7 parser, generator and sender.

1951.3M](/packages/aranyasen-hl7)[gioni06/gpt3-tokenizer

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

85537.5k8](/packages/gioni06-gpt3-tokenizer)[rickselby/nbt

Parser/Writer for the NBT file format

171.2k1](/packages/rickselby-nbt)[nihongodera/limelight

A php Japanese language text analyzer and parser.

10678.9k](/packages/nihongodera-limelight)[kherge/json

Encodes, decodes, and validates JSON data.

61226.6k6](/packages/kherge-json)

PHPackages © 2026

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