Download the PHP package dynoser/helml without Composer
On this page you can find all versions of the php package dynoser/helml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dynoser/helml
More information about dynoser/helml
Files in dynoser/helml
Informations about the package helml
HELML
PHP package
Implementations
Installation (PHP)
To install HELML, simply use composer:
or, You may copy and use files directly:
Usage
This package contains two independent classes:
- class
HELML
- encoder/decoder HELML-format - class
fileHELMLsect
- selective data-section loader from HELML file
class HELML
Here's a quick example of how to use the HELML
class:
encoded_data:
Features
Encode and decode data arrays to/from HELML.
API
HELML::encode
($arr, $url_mode=False)
Encode a data array into a HELML string.
- $arr The input data array to be encoded.
- $url_mode (bool, optional): A boolean indicating if the URL mode should be used. Defaults to False.
Returns:
- string: The encoded HELML string.
HELML::decode
($src_rows)
Decode a HELML formatted string or list of strings into a nested dictionary.
- $src_rows The HELML input as a string or strings-array.
Returns:
- Array: The decoded nested array.
Class fileHELMLsect
This class implements selective loading of sections from a file in HELML format.
Result string:
In result we got data only from 'B', 'C' and 'D' sections, without comments and empty-lines
In this way, it is very convenient to get sections from the root level.
You can get nested keys in exactly the same way, however, it should be remembered that we will get these structures without the structures in which they are located.
For example, we can get ':nested' key from previous example file, and we got:
Result:
The parsing of this sample will be as follows:
Note:
- Specifying "
:
" at the end of the section name is optional. Inside these colons are removed. - All the level colons at the beginning need to be specified if we want to get a non-root level section.
- Parameter
$only_first_occ
, which allows you to get all occurrences of the listed sections, if there are several of them in the file
By setting the $only_first_occ
parameter to false
, you can extract all variants of the values of some nested key.
For example, let's get all the values of the nested key X from the examples above:
Result:
Independence
- Note that both classes
HELML
andfileHELMLsect
do not have any dependencies and can be used independently of each other.
See also:
- plugin "HELML" for Visual Studio Code
- Try online HELML plugin in vscode.dev
License
This project is licensed under the Apache-2 License.