This is documentation for Kohana v2.3.x.
Status | Draft |
---|---|
Todo | Proof read |
Provides methods for working with Text.
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
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
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
text::random()
accepts multiple optional parameters.
Returns a random text string of specified length.
Possible values for $type are:
alnum
- 0-9, a-z and A-Zalpha
- a-z, A-Znumeric
- 0-9nozero
- 1-9distinct
- Only distinct characters that can't be mistaken for others.echo text::random($type = 'alnum', $length = 10);
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 ?>
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 ****.
Finds the text that is similar between a set of words.
Converts text email addresses and anchors into links.
Converts text anchors into links.
Converts text email addresses into links.
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
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);
Automatically applies <p> and <br /> markup to text. Basically nl2br() on steroids.