2017 © Pedro Peláez
 

library text

Some handy text processing utilities

image

kuz/text

Some handy text processing utilities

  • Friday, August 16, 2013
  • by akuzemchak
  • Repository
  • 1 Watchers
  • 3 Stars
  • 134 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

Kuz Text Utilities

Build Status, (*1)

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

Installation

Use Composer. Seriously., (*3)

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

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

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>

The Versions

16/08 2013

dev-master

9999999-dev

Some handy text processing utilities

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

text format processing nl2br replace nl2p

16/08 2013

v0.1.1

0.1.1.0

Some handy text processing utilities

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

text format processing nl2br replace nl2p

25/07 2013

v0.1.0

0.1.0.0

Some handy text processing utilities

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

text format processing nl2br replace nl2p