\Pluf_Text

Utility class to clean/manipulate strings.

Summary

Methods
Properties
Constants
wrapHtml()
tokenize()
cleanString()
removeAccents()
stringToChars()
preventUpperCase()
simplePreventUpperCase()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

wrapHtml()

wrapHtml(  $string,   $length = 45,   $wrapString = "\n") : string

Wrap a string containing HTML code.

The HTML is not broken, words are broken only if very long.

Improved from a version available on php.net

Parameters

$string
$length
$wrapString

Returns

string —

Wrapped string

tokenize()

tokenize(  $string,   $remove_accents = True) : array

Given a string, cleaned from the not interesting characters, returns an array with the words as index and the number of times it was in the text as the value.

Parameters

$string
$remove_accents

Returns

array —

Word and number of occurences.

cleanString()

cleanString(  $string) : string

Clean a string from the HTML and the unnecessary punctuation. Convert the string to lowercase.

Parameters

$string

Returns

string —

Cleaned lowercase string.

removeAccents()

removeAccents(  $string) : string

Remove the accentuated characters.

Requires a string in lowercase, the removal is not perfect but is better than nothing.

Parameters

$string

Returns

string —

String with some of the accents removed.

stringToChars()

stringToChars(  $string) : array

Convert a string to a list of characters.

Parameters

$string

Returns

array —

Characters.

preventUpperCase()

preventUpperCase(  $string,   $mode = MB_CASE_TITLE) : string

Prevent a string to be all uppercase.

If more than 50% of the words in the string are uppercases and if the string contains more than one word, the string is converted using the mb_convert_case.

Parameters

$string
$mode

Returns

string —

Cleaned string.

simplePreventUpperCase()

simplePreventUpperCase(  $string,   $mode = MB_CASE_TITLE) : string

Simple uppercase prevention.

Contrary to self::preventUpperCase, this method will also prevent a single word to be uppercase.

Parameters

$string
$mode

Returns

string —

Mode cased if all uppercase in input.