String manipulation, leveled up! -- by, Chris Kankiewicz (@PHLAK)
Twine is a simple string manipulation library with an expressive, fluent syntax.
Like this project? Keep me caffeinated by making a donation.
- PHP >= 7.0
composer require phlak/twine
First, import Twine:
use PHLAK\Twine;
Then instantiate a Twine string:
$string = new Twine\Str('john pinkerton');
// or statically via the make() method
$string = Twine\Str::make('john pinkerton');
// or with the str() helper method
$string = str('john pinkerton');
More details available at https://twine.phlak.net/docs/usage/
after • append • base64 • base64Decode • base64Encode • bcrypt • before • camelCase • contains • count • crc32 • crypt • decrypt • echo • encrypt • endsWith • equals • first • format • from • hex • hexEncode • hexDecode • insensitiveMatch • insert • join • kebabCase • last • length • lowercase • matches • md5 • pad • padBoth • padLeft • padRight • pascalCase • prepend • repeat • replace • reverse • sha1 • sha256 • shuffle • similarity • snakeCase • startsWith • strip • studlyCase • substring • trim • trimLeft • trimRight • truncate • uppercase • url • words • wrap • wrapHard • wrapSoft
Full documentation available at https://twine.phlak.net
A Twine string can be manipulated fluently by chaining methods. Here are a few example chains:
Perform a substring comparison:
$string = new Twine\Str('john pinkerton');
$string->substring(5, 4)->equals('pink'); // Returns true
Encode a file in compliance with RFC 2045.
$string = new Twine\Str(file_get_contents('garbage.bin'));
$string->base64()->wrap(76, "\r\n", Twine\Config\Wrap::HARD);
A list of changes can be found on the GitHub Releases page.
Please report bugs to the GitHub Issue Tracker.
This project is licensed under the MIT License.