gregorj / to-string
A simple PHP library for turning values into readable strings.
v1.1.0
2026-09-03 16:25 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpstan/phpstan: ^2.2.3
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-03 16:27:57 UTC
README
This is a simple PHP library for turning values into readable strings. Its main purpose is to make strings and byte data printable by escaping non-printable characters instead of returning raw control bytes. This means, binary data is supported.
The library currently provides helpers for:
- booleans
- bytes
- strings
- arrays
- generic
mixedvalues
Installation
composer require gregorj/to-string
Usage
<?php use GregorJ\ToString\ToString; echo ToString::fromAny(true); // true echo ToString::fromAny("hello\nworld"); // hello\nworld echo ToString::fromAny(['name' => 'Hello', 'value' => 2.7, 'nothing' => null]); // [name: "Hello", value: 2.7, nothing: null] echo ToString::fromAny(new stdClass()); // stdClass
Limitations
- Array output is currently designed for human readability, not for parsing back into PHP.
- Recursive/self-referencing arrays are currently not supported.
Development
All development commands (install, test, lint, analyze, beautify, sniff, audit,
validate) run via Docker through the Makefile, so no local PHP installation is
needed. Run make help to list all targets.
Most local targets require PHP_VERSION, for example:
make install PHP_VERSION=8.1