2017 © Pedro Peláez
 

library text

Simple text manipulation library for PHP5.4

image

kzykhys/text

Simple text manipulation library for PHP5.4

  • Sunday, August 25, 2013
  • by kzykhys
  • Repository
  • 4 Watchers
  • 48 Stars
  • 542 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 11 Forks
  • 2 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

Text - Simple 1 Class Text Manipulation Library

Latest Stable Version Build Status Coverage Status, (*1)

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

Text is extracted from kzykhys/Ciconia. this is used for markdown processing., (*3)

Installation

Modify your composer.json and run php composer.phar update, (*4)

``` json { "require": { "kzykhys/text":"~1.0.0" } }, (*5)


Requirements ------------ **PHP5.4+** Get Started ----------- `Text` acts like a string

<?php, (*6)

use KzykHys\Text\Text;, (*7)

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

// Lorem Ipsum, (*9)


`Text` can also be called statically

<?php, (*10)

use KzykHys\Text\Text;, (*11)

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

// Lorem Ipsum, (*13)


Manipulation methods are *chainable*: ``` php $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(), (*14)

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

// BARbaz ```, (*16)

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

API

Manipulation (Chainable)

Method Description
create($text) Create a new Text instance.
append($text) Append the string.
prepend($text) Prepend the string.
wrap($start, [$end]) Surround text with given string.
lower() Make a string lowercase.
upper() Make a string uppercase.
trim([$charList]) Strip whitespace (or other characters) from the beginning and end of a string.
rtrim([$charList]) Strip whitespace (or other characters) from the end of a string.
ltrim([$charList]) Strip whitespace (or other characters) from the beginning of a string.
escapeHtml([$option]) Convert special characters to HTML entities.
replace($pattern, $replacement) Perform a regular expression search and replace. If $replacement is the callable, a callback that will be called and passed an array of matched elements in the subject string.
replaceString($search, $replace) Replace all occurrences of the search string with the replacement string.
indent([$spaces]) Add one level of line-leading spaces.
outdent([$spaces]) Remove one level of line-leading tabs or spaces.
detab([$spaces]) Convert tabs to spaces.
eachLine($callback) Apply a user function to every line of the string.

Test

Method Description
isEmpty() Determine whether a variable is empty
isNumeric() Finds whether a variable is a number or a numeric string
match($pattern, [&$matches]) Perform a regular expression match

Miscellaneous

Method Description
split($pattern, [$flags]) Split string by a regular expression
lines([$pattern]) Split string by a line break
chars() Convert a string to an array
length() Gets the length of a string
countLines() Gets the number of lines
indexOf($needle, [$offset]) Find the position of the first occurrence of a substring in a string

Filesystem

Method Description
save($path) Write a string to a file

License

The MIT License, (*18)

Author

Kazuyuki Hayashi (@kzykhys), (*19)

The Versions

25/08 2013

dev-master

9999999-dev

Simple text manipulation library for PHP5.4

  Sources   Download

MIT

by Kazuyuki Hayashi

text box

25/08 2013

v1.0.1

1.0.1.0

Simple text manipulation library for PHP5.4

  Sources   Download

MIT

by Kazuyuki Hayashi

text box

07/08 2013

v1.0.0

1.0.0.0

Simple text manipulation library for PHP5.4

  Sources   Download

MIT

by Kazuyuki Hayashi

text box