{"id":25005653,"url":"https://github.com/brandonxlf/nbt.php","last_synced_at":"2025-04-12T14:43:10.039Z","repository":{"id":62496657,"uuid":"255733348","full_name":"BrandonXLF/NBT.php","owner":"BrandonXLF","description":"A library to convert NBT data to PHP data","archived":false,"fork":false,"pushed_at":"2020-10-21T01:39:08.000Z","size":14,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T08:38:25.610Z","etag":null,"topics":["minecraft","nbt","nbt-library","nbt-parser","php","php-library"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/brandon/nbt","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrandonXLF.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-14T21:42:53.000Z","updated_at":"2024-02-23T19:43:45.000Z","dependencies_parsed_at":"2022-11-02T10:00:37.022Z","dependency_job_id":null,"html_url":"https://github.com/BrandonXLF/NBT.php","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrandonXLF%2FNBT.php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrandonXLF%2FNBT.php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrandonXLF%2FNBT.php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrandonXLF%2FNBT.php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrandonXLF","download_url":"https://codeload.github.com/BrandonXLF/NBT.php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248583587,"owners_count":21128623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["minecraft","nbt","nbt-library","nbt-parser","php","php-library"],"created_at":"2025-02-05T00:47:04.873Z","updated_at":"2025-04-12T14:43:10.014Z","avatar_url":"https://github.com/BrandonXLF.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NBT to PHP\n\nNBT to PHP allows you to convert NBT data to PHP data types to easily use within a PHP program.\n\n## Introduction\n\nSince 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.\n\nAn 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.\n\nAn 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).\n\n## Installation\n\n## Composer\n\nThis library can be downloaded using [Composer](https://getcomposer.org/). For example you can add the following to your `composer.json` file.\n\n```json\n{\n    \"require\": {\n        \"brandon/nbt\": \"*\"\n    }\n}\n```\n\nIt is recommended to replace `*` with a version constraint.\n\n## Git\n\nThere are several ways to download directly from GitHub, the only required file is `NBT.php`.\n\n- Download `NBT.php` via https://raw.githubusercontent.com/BrandonXLF/NBT.php/master/NBT.php\n- Clone repository using `git clone https://github.com/BrandonXLF/NBT.php`\n- Download code from GitHub\n\nAfter downloading, to use the library you would use:\n```php\nrequire 'NBT.php';\n```\n\n## Documentation\n\nAs 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.\n\nThere are 3 main functions that you should access, `NBT::readFile`, `NBT::readString`, and `NBT::readStream`.\n\n### NBT::readFile\n\nNBT::readFile is used to read NBT data from a file.\n\n```php\nNBT::readFile( string $filename, string $wrapper = 'compress.zlib://' ) : array\n```\n\n#### Parameters\n\n* **$filename** - The name of the file to read from\n* **$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.\n\n#### Returns\n\nAn array with the NBT data converted to PHP.\n\n### NBT::readString\n\nNBT::readString is used to read NBT data from a string.\n\n```php\nNBT::readString( string $str ) : array\n```\n\n#### Parameters\n\n* **$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.\n\n#### Returns\n\nAn array with the NBT data converted to PHP.\n\n### NBT::readStream\n\nNBT::readStream is used to read NBT data from a file stream.\n\n```php\nNBT::readStream( resource $stream ) : array\n```\n\n#### Parameters\n\n* **$str** - A binary\n file stream to read the NBT data from.\n\n#### Returns\n\nAn array with the NBT data converted to PHP.\n\n### NBT::readTag\n\nNBT::readTag is used to read a NBT tag from a file stream.\n\n```php\nNBT::readTag( int $type, resource $stream ) : mixed\n```\n\n#### Parameters\n\n* **$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.\n* **$stream** - The file stream to read from.\n\n#### Returns\n\nThe NBT data read as PHP data, return type depends on the `$type` parameter.\n\n## Testing\n\nTests for this script can be found in the `tests/test.php` php file. You may run `php tests/test.php` to test this script.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonxlf%2Fnbt.php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandonxlf%2Fnbt.php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonxlf%2Fnbt.php/lists"}