String manipulation, leveled up!
Clone or download
PHLAK Various improvements
  - Improved some multibyte support
  - Improved performance of some methods
  - Reduced some code duplication
Latest commit 23c161e Nov 4, 2018
Permalink
Failed to load latest commit information.
src Various improvements Nov 4, 2018
tests Various improvements Nov 4, 2018
.gitattributes Added a .gitattributes file Jul 4, 2017
.gitignore
.php_cs.dist Disabled incerment style enforcement in php-cs-fixer Sep 17, 2018
.styleci.yml Added .styleci.yml config file Jul 12, 2018
.travis.yml Removed before_install from travis config Jul 17, 2018
LICENSE Updated copyright year in the LICENSE Jul 5, 2018
README.md Updated documentation link Sep 21, 2018
composer.json Test enhancement Oct 26, 2018
demo.gif Added demo gif to the README Jul 6, 2018
phpunit.xml Added code coverage filter to phpunit.xml Sep 16, 2017
twine.png Replaced twine.svg with twine.png Jul 4, 2017

README.md

Twine

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.