phlak/twine

String manipulation, leveled up!

3.1.0 2018-11-01 23:46 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.

Twine Demo

Like this project? Keep me caffeinated by making a donation.

Requirements

Install with Composer

composer require phlak/twine

Getting Started

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/

Available Methods

afterappendbase64base64Decodebase64EncodebcryptbeforecamelCasecontainscountcrc32cryptdecryptechoencryptendsWithequalsfirstformatfromhexhexEncodehexDecodeinsensitiveMatchinsertjoinkebabCaselastlengthlowercasematchesmd5padpadBothpadLeftpadRightpascalCaseprependrepeatreplacereversesha1sha256shufflesimilaritysnakeCasestartsWithstripstudlyCasesubstringtrimtrimLefttrimRighttruncateuppercaseurlwordswrapwrapHardwrapSoft

Full documentation available at https://twine.phlak.net

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

Changelog

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

Troubleshooting

Please report bugs to the GitHub Issue Tracker.

Copyright

This project is licensed under the MIT License.