PHPackages                             kuz/text - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kuz/text

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

kuz/text
========

Some handy text processing utilities

v0.1.1(12y ago)31681MITPHPPHP &gt;=5.3

Since Jul 25Pushed 12y ago1 watchersCompare

[ Source](https://github.com/akuzemchak/text)[ Packagist](https://packagist.org/packages/kuz/text)[ RSS](/packages/kuz-text/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (1)

Kuz Text Utilities
==================

[](#kuz-text-utilities)

[![Build Status](https://camo.githubusercontent.com/bbc4dcc3d1e18bf3360f9d6e335eee6ebc9406499f8d8e9ef02967b55ca92e5b/68747470733a2f2f7472617669732d63692e6f72672f616b757a656d6368616b2f746578742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/akuzemchak/text)

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
------------

[](#installation)

Use [Composer](http://getcomposer.org/). Seriously.

```
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require kuz/text
$ php composer.phar install

```

Kuz\\Text::format()
-------------------

[](#kuztextformat)

```
string Kuz\Text::format( string $subject , array $replacements [, string $prefix = ':'] )

```

The `Text::format()` method is similar to PHP's native [`sprintf`](http://php.net/sprintf) or [`vsprintf`](http://php.net/vsprintf) functions, but more fun to use.

### Replace named placeholders

[](#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

[](#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

[](#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

[](#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()
-----------------

[](#kuztextnl2p)

```
string Kuz\Text::nl2p( string $text [, bool $xhtml = false] )

```

The `Text::nl2p()` method takes PHP's [`nl2br`](http://php.net/nl2br) function a step further, by wrapping blocks of text in `` tags.

### Basic usage example

[](#basic-usage-example)

```
$text =
