This is documentation for Kohana v2.3.x.

Table of Contents
StatusDraft
TodoProof read

Text Helper

Provides methods for working with Text.

Methods

limit_words()

text::limit_words() accepts multiple parameters. Only the input string is required. The default end character is the ellipsis.

$long_description = 'The rain in Spain falls mainly in the plain';
$limit = 4;
$end_char = ' ';
 
$short_description = text::limit_words($long_description, $limit, $end_char);

Generates:

The rain in Spain

limit_chars()

text::limit_chars() accepts multiple parameters. Only the input string is required. The default end character is the ellipsis.

$long_description = 'The rain in Spain falls mainly in the plain';
$limit = 4;
$end_char = ' ';
$preserve_words = FALSE;
 
$short_description = text::limit_chars($long_description, $limit, $end_char, $preserve_words);

Generates:

The r

alternate()

text::alternate() accepts multiple parameters. The number of parameters determines the alternation. This is handy if you loop through something and you for example want to alternate the color of a table row.

for($i=0:$i<5:$i++)
{
    echo text::alternate('1','2','boom');
}
//returns 12boom12

random()

text::random() accepts multiple optional parameters. Returns a random text string of specified length.

Possible values for $type are:

echo text::random($type = 'alnum', $length = 10);

reduce_slashes()

text::reduce_slashes() reduces multiple slashes in a string to single slashes.

<?php
$str = "path/to//something";
echo reduce_slashes($str); // Outputs: path/to/something
?>

censor()

text::censor() accepts multiple optional parameters. The input string and an array of marker words is required. Returns a string with the marker words censored by the specified replacement character.

$str = 'The income tax is a three letter word, but telemarketers are scum.';
$replacement = '*';
$badwords = array('tax', 'scum');
 
echo text::censor($str, $badwords, $replacement, $replace_partial_words = FALSE);

Generates:

The income *** is a three letter word, but telemarketers are ****.

similar()

Finds the text that is similar between a set of words.

auto_link()

Converts text email addresses and anchors into links.

auto_link_urls()

Converts text anchors into links.

auto_link_emails()

Converts text email addresses into links.

bytes()

text::bytes($bytes,$force_unit,$format,$si) Returns a human readable size.

echo text::bytes('2048'); //returns 2.05 kB
echo text::bytes('4194304','kB'); //returns 4194.30 kB
echo text::bytes('4194304','GiB'); //returns 0.00 GiB
echo text::bytes('4194304',NULL, NULL, FALSE); //returns 4.00 MiB

widont()

text::widont() Returns a string without widow words by inserting a non-breaking space between the last two words. A widow word is a single word at the end of a paragraph on a new line. It's considered bad style.

$paragraph='Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras id dolor. Donec ...';
 
$paragraph=text::widont($paragraph);

auto_p()

Automatically applies <p> and <br /> markup to text. Basically nl2br() on steroids.