kzykhys / text
Simple text manipulation library for PHP5.4
Installs: 3 834
Dependents: 1
Suggesters: 0
Security: 0
Stars: 53
Watchers: 5
Forks: 8
Open Issues: 2
This package is not auto-updated.
Last update: 2024-12-16 15:18:26 UTC
README
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)