kzykhys/text

Simple text manipulation library for PHP5.4

v1.0.1 2013-08-25 05:34 UTC

This package is not auto-updated.

Last update: 2024-11-04 14:52:07 UTC


README

Latest Stable Version Build Status Coverage Status

Do you remember PHP's string functions? If not, just wrap you text with Text! It will save a minute on your coding.

Text is extracted from kzykhys/Ciconia. this is used for markdown processing.

Installation

Modify your composer.json and run php composer.phar update

{
    "require": {
        "kzykhys/text":"~1.0.0"
    }
}

Requirements

PHP5.4+

Get Started

Text acts like a string

<?php

use KzykHys\Text\Text;

$text = new Text('Lorem Ipsum');
echo $text;

// Lorem Ipsum

Text can also be called statically

<?php

use KzykHys\Text\Text;

$text = Text::create('Lorem Ipsum');
echo $text;

// Lorem Ipsum

Manipulation methods are chainable:

$text = new Text('foo');
$text
    ->append('bar')     // foobar
    ->prepend('baz')    // bazfoobar
    ->wrap('-')         // -bazfoobar-
    ->upper()           // -BAZFOOBAR-
    ->lower()           // -bazfoobar-
    ->trim('-')         // bazfoobar
    ->rtrim('r')        // bazfooba
    ->ltrim('b')        // azfooba
;

Special note for replace()

$text = new Text('FooBarBaz');
$text->replace('/Foo(Bar)(Baz)/', function (Text $whole, Text $bar, Text $baz) {
    return $bar->upper()->append($baz->lower());
});
echo $text;

// BARbaz

If the second argument is callable, callback takes at least one parameter. The whole match being first, and matched subpatterns. All parameters are Text instance.

API

Manipulation (Chainable)

Test

Miscellaneous

Filesystem

License

The MIT License

Author

Kazuyuki Hayashi (@kzykhys)