Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/perryvw/phpvalvekv
A parser for Valve's KV format, written in PHP.
https://github.com/perryvw/phpvalvekv
parser php serialization valve
Last synced: 4 months ago
JSON representation
A parser for Valve's KV format, written in PHP.
- Host: GitHub
- URL: https://github.com/perryvw/phpvalvekv
- Owner: Perryvw
- License: mit
- Created: 2017-06-16T19:41:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-11-30T12:46:04.000Z (about 1 year ago)
- Last Synced: 2024-05-01T12:41:30.194Z (10 months ago)
- Topics: parser, php, serialization, valve
- Language: PHP
- Size: 617 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHPValveKV
A parser for Valve's KeyValue serialization format, written in PHP.The parser supports parsing from files and strings. It can deal with most of the quirks of the Valve KV language such as conditionals, un-quoted keys or values, #base includes.
Thanks to [xPaw](https://github.com/xPaw) for his help and the [ValveKeyValue](https://github.com/SteamDatabase/ValveKeyValue) project for their testcases.
# Typed version available
This library is available with typed properties on the [typed-at-php7.4](https://github.com/Perryvw/PHPValveKV/tree/typed-at-php7.4) branch. This version will only work with php version >= 7.4!## Usage
```php
require "valveKV.php";// Create a parser instance.
$parser = new \ValveKV\ValveKV();
// Parse a KV string.
$kvFromString = $parser->parseFromString('"root"{"A" "B"}');
// Parse a KV file.
$kvFromFile = $parser->parseFromFile("myKVFile.txt");// Parse while merging the values of duplicate keys.
$kvFromFile2 = $parser->parseFromFile("myKVFile.txt", true);
```### Duplicate keys
The KV format can contain duplicate keys. By default, the value of duplicate keys will be transformed into a list of its different values. The functions `parseFromString` and `parseFromFile` both have a flag `mergeDuplicates` that merges the values of duplicate keys (if they are arrays) instead of adding them to a list.## Test status
Currently the parser is covered by a large amount of test cases that all pass.