phlak/twine

String manipulation, leveled up!

Maintainers

Details

github.com/PHLAK/Twine

Source

Issues

Installs: 7 376

Dependents: 3

Suggesters: 0

Stars: 436

Watchers: 14

Forks: 22

Open Issues: 0

4.0.0 2018-11-21 21:55 UTC

README

Twine

Latest Stable Version Total Downloads Author License Build Status StyleCI

String manipulation, leveled up! -- by, Chris Kankiewicz (@PHLAK)

Introduction

Twine is a simple string manipulation library with an expressive, fluent syntax.

Like this project?

Join the community on Spectrum Become a Patron One-time Donation

Requirements

Install with Composer

composer require phlak/twine

Getting Started

First, import Twine:

use PHLAK\Twine;

Then instantiate a Twine object by newing up a Twine\Str object and passing your string as the first parameter.

$string = new Twine\Str('john pinkerton');

You may also instantiate a Twine\Str object statically via the make() method.

$string = Twine\Str::make('john pinkerton');

Or use the global str() helper method. The method takes a string as the only parameter and returns a Twine\Str object.

$string = str('john pinkerton');

Once you have a concrete Twine\Str instance you may treat it like any other string. This includes echoing it or using any of PHP's built in string functions against it.

echo $string; // Echos 'john pinkerton'

str_shuffle($string) // Returns something like 'enoipo ktnjhnr'

strlen($string); // Returns 14

At this point you're ready to start using Twine by calling any of its many built in methods.

Available Methods

afterappendbase64base64Decodebase64EncodebcryptbeforecamelCasecharacterschunkcontainscountcrc32cryptdecryptechoencodingencryptendsWithequalsexplodefirstformatfromhexhexEncodehexDecodeinsensitiveMatchinsertinisAlphabeticisAlphanumericisEmptyisLowercaseisNotEmptyisNumericisPrintableisPunctuationisUppercaseisWhitespacejoinkebabCaselastlengthlowercaselowercaseFirstlowercaseWordsmatchesmd5nthpadpadBothpadLeftpadRightpascalCaseprependrepeatreplacereversesha1sha256shufflesimilaritysnakeCasesplitstartsWithstripstudlyCasesubstringtotrimtrimLefttrimRighttruncateuppercaseuppercaseFirstuppercaseWordsurlwordswrapwrapHardwrapSoft

Method Chaining

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);

Additional details available in the full documentation at https://twine.phlak.net.

Changelog

A list of changes can be found on the GitHub Releases page.

Troubleshooting

For general help and support join our Spectrum community.

Please report bugs to the GitHub Issue Tracker.

Copyright

This project is licensed under the MIT License.