https://github.com/sevenecks/string-utils
PHP String Utility Package loosely based on LambdaMOO $string_utils package. Useful for formatting strings for logs and terminal output.
https://github.com/sevenecks/string-utils
formatting lambdamoo logging php string terminal
Last synced: about 2 months ago
JSON representation
PHP String Utility Package loosely based on LambdaMOO $string_utils package. Useful for formatting strings for logs and terminal output.
- Host: GitHub
- URL: https://github.com/sevenecks/string-utils
- Owner: sevenecks
- License: mit
- Created: 2017-12-12T15:53:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-18T20:08:17.000Z (over 7 years ago)
- Last Synced: 2025-02-21T23:18:00.334Z (over 1 year ago)
- Topics: formatting, lambdamoo, logging, php, string, terminal
- Language: PHP
- Size: 122 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# StringUtils
A set of common string functions, loosely based on LambdaMOO $string_utils. It uses [sevenecks/ansi](https://github.com/SevenEcks/ansi) to add color where applicable though you can pass your own colorizer in via dependency injection.
## Installation
Via Composer
```bash
composer require sevenecks/string-utils
```
## Usage
```php
require_once __DIR__ . '/../vendor/autoload.php';
use SevenEcks\StringUtils\StringUtils;
use SevenEcks\Ansi\Colorize;
$su = new StringUtils;
$test_string = 'This is a test';
// echo out test string
$su->tell($test_string);
$su->setLineLength(10);
// echo out a string, ignores line len
$su->tell($su->colorize->red("This is a test of a long red string!"));
$su->setSplitMidWord(true);
// echo using line length and color color
$su->tell($su->colorize->red($su->wordWrap("This is a test of a long blue word wrapped string which breaks mid word!")));
$su->setSplitMidWord(false);
// echo using length and color color
$su->tell($su->colorize->blue($su->wordWrap("This is a test of a long blue word wrapped string which breaks at a word!")));
// set the line length break string to br instead of default of \n
$su->setBreakString("
");
$su->tell($su->colorize->red($su->wordWrap("This is a test of a long red string!")));
$su->tell("Not colored.");
// mass colorize a string wrapped by line
$su->tell_lines($su->massColor($su->lineWrap("This is a test of a long line wrapped red strings!"), 'blue'));
// break at specific linelen
$su->tell_lines($su->lineWrap('123456789123456789123456789'));
// formatting of left, right, and center
$su->tell($su->left("TEST", 10) . $su->left("TEST1", 10));
$su->tell($su->right("TEST", 10) . $su->right("TEST1", 10));
$su->tell($su->center("TEST", 10) . $su->center("TEST1", 10));
// update line len
$su->setLineLength(180);
// center
$su->tell($su->center("CENTER NO ARGS"));
$su->tell($su->center("CENTER W/ ARGS", 30));
// alerts crits and warnings for debugging
$su->alert("This is an alert!");
$su->warning("This is a warning");
$su->critical("This is critical!");
// using tostr to combine args into a string
$su->tell($su->tostr($su->center("THIS EXAMPLE", 10), ' ', $su->center("USES TOSTR", 10), ' ', 1,2,3));
$su->tell($su->tostr('1',2,'3','asdf',['a', 'b' => 'c', 1]));
```

## Change Log
Please see [Change Log](CHANGELOG.md) for more information.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.