2017 © Pedro Peláez
 

library twine

String manipulation, leveled up!

image

phlak/twine

String manipulation, leveled up!

  • Monday, July 30, 2018
  • by PHLAK
  • Repository
  • 9 Watchers
  • 313 Stars
  • 347 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 15 Forks
  • 2 Open issues
  • 10 Versions
  • 11467 % Grown

The README.md

Twine , (*1)

String manipulation, leveled up! -- by, Chris Kankiewicz (@phlak.dev) , (*2)

Join the Community Become a Sponsor One-time Donation
Latest Stable Version Total Downloads License Test Suite , (*3)


Introduction

Twine is a string manipulation library with an expressive, fluent syntax., (*4)

Requirements

Install with Composer

composer require phlak/twine

Getting Started

First, import Twine:, (*5)

use PHLAK\Twine;

Then instantiate a Twine object by newing up a Twine\Str object and passing your string as the first parameter., (*6)

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

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

$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., (*8)

$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., (*9)

echo $string; // Echos 'john pinkerton'

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

strlen($string); // Returns 14

The strength of Twine, however comes from its built-in methods., (*10)

$string->echo(); // Echos 'john pinkerton'
$string->shuffle(); // Returns something like 'enoipo ktnjhnr'
$string->length(); // Returns 14

// or some more interesting methods

$string->reverse(); // Returns 'notreknip nhoj'
$string->contains('pink'); // Returns true
$string->replace('pink', 'purple'); // Returns 'john purpleton'
$string->snakeCase(); // Returns 'john_pinkerton'

At this point you're ready to start using Twine by calling any of its many built-in methods., (*11)

Available Methods

afterappendbase64base64Decodebase64EncodebcryptbeforecamelCasecharacterschunkcontainscountcrc32cryptdecryptechoencodingencryptendsWithequalsexplodefirstformatfromhexhexEncodehexDecodeinsensitiveMatchinsertinisAlphabeticisAlphanumericisEmptyisLowercaseisNotEmptyisNumericisPrintableisPunctuationisUppercaseisWhitespacejoinkebabCaselastlengthlowercaselowercaseFirstlowercaseWordsmatchmatchAllmatchesmd5nthpadpadBothpadLeftpadRightpascalCaseprependrepeatreplacereversesha1sha256shufflesimilaritysnakeCasesplitstartsWithstripstudlyCasesubstringtotrimtrimLefttrimRighttruncateuppercaseuppercaseFirstuppercaseWordsurlwordswrapwrapHardwrapSoft, (*12)


Method Chaining

A Twine string can be manipulated fluently by chaining methods. Here are a few example chains:, (*13)

Perform a substring comparison:, (*14)

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

$string->substring(5, 4)->equals('pink'); // Returns true

Encode a file in compliance with RFC 2045., (*15)

$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., (*16)

MultiByte Strings

Twine aims for multibyte string compatibility by relying on PHP's Multibyte String extension (mbstring) to perform string operations. For this reason, the mbstring extension is required. Multibyte strings include Unicode encodings such as UTF-8 and UCS-2., (*17)

Changelog

A list of changes can be found on the GitHub Releases page., (*18)

Troubleshooting

For general help and support join our GitHub Discussion or reach out on Bluesky., (*19)

Please report bugs to the GitHub Issue Tracker., (*20)

This project is licensed under the MIT License., (*21)

The Versions

30/07 2018

dev-dev/2.3.0

dev-dev/2.3.0

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

22/07 2018

dev-master

9999999-dev

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

22/07 2018

2.2.0

2.2.0.0

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

17/07 2018

2.1.0

2.1.0.0

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

08/07 2018

2.0.0

2.0.0.0

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

11/09 2017

1.0.0

1.0.0.0

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

04/09 2017

0.2.0

0.2.0.0

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

21/08 2017

0.1.2

0.1.2.0

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

29/07 2017

0.1.1

0.1.1.0

String manipulation, leveled up!

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

04/07 2017

0.1.0

0.1.0.0

Strings, leveled up

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires