Download the PHP package kuz/text without Composer
On this page you can find all versions of the php package kuz/text. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package text
Kuz Text Utilities
This is a simple PHP class that adds a few helper methods for performing different actions on text. Nothing too fancy, but should be helpful to someone other than me.
Installation
Use Composer. Seriously.
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require kuz/text
$ php composer.phar install
Kuz\Text::format()
string Kuz\Text::format( string $subject , array $replacements [, string $prefix = ':'] )
The Text::format()
method is similar to PHP's native sprintf
or vsprintf
functions, but more fun to use.
Replace named placeholders
$subject = 'My name is :name, and I am a :title.';
$replacements = ['name' => 'Aaron', 'title' => 'Code Monkey'];
echo Kuz\Text::format($subject, $replacements);
// My name is Aaron, and I am a Code Monkey.
Replace numeric placeholders
$subject = 'My name is :0, and I am a :1.';
$replacements = ['Aaron', 'Code Monkey'];
echo Kuz\Text::format($subject, $replacements);
// My name is Aaron, and I am a Code Monkey.
Replace multiple occurrences
$subject = ':0 plus :0 equals :1';
$replacements = [3, 6];
echo Kuz\Text::format($subject, $replacements);
// 3 plus 3 equals 6
Use custom identifiers
$subject = 'My name is %name, and I am a %title.';
$replacements = ['name' => 'Aaron', 'title' => 'Code Monkey'];
echo Kuz\Text::format($subject, $replacements, '%');
// My name is Aaron, and I am a Code Monkey.
Kuz\Text::nl2p()
string Kuz\Text::nl2p( string $text [, bool $xhtml = false] )
The Text::nl2p()
method takes PHP's nl2br
function a step further, by wrapping blocks of text in <p></p>
tags.
Basic usage example
$text = <<<EOD
Hello.
This is some placeholder text. It should be a new paragraph.
As should this.
As should this.
But this one has a line break as well.
EOD;
echo Kuz\Text::nl2p($text);
// <p>Hello.</p>
//
// <p>This is some placeholder text. It should be a new paragraph.</p>
//
// <p>As should this.</p>
//
// <p>As should this.<br>
// But this one has a line break as well.</p>
Want XHTML style <br>
tags?
$text = <<<EOD
This is a paragraph...
With a line break!
EOD;
echo Kuz\Text::nl2p($text, true);
// <p>This is a paragraph...<br />
// With a line break!</p>
All versions of text with dependencies
PHP Build Version
Package Version
Requires
php Version
>=5.3
The package kuz/text contains the following files
Loading the files please wait ....