This is documentation for Kohana v2.3.x.

Table of Contents
StatusFirst Draft
TodoExpand, fill in missing methods

Unicode Functions

Provides static methods to work with UTF-8 strings as PHP is not yet natively capable of doing that.

Requirements:

Methods

clean

utf8::clean() recursively cleans arrays, objects, and strings. It removes ASCII control characters (strip_ascii_ctrl) and converts to UTF-8 while silently discarding incompatible UTF-8 characters.

Note:

The clean() method is automatically applied to the GET, POST, COOKIE and SERVER globals.

from_unicode

is_ascii

utf8::is_ascii() checks whether a string contains only 7bit ASCII bytes. It returns TRUE if it does so, FALSE otherwise. This method is also used internally in the utf8 class to determine when to use native functions or UTF-8 functions.

Example:

var_dump(utf8::is_ascii("a\0b".chr(127).'c')); // bool(true)
var_dump(utf8::is_ascii("a\0b".chr(128).'c')); // bool(false)

ltrim

ord

rtrim

str_ireplace

str_pad

str_split

strcasecmp

strcspn

strip_ascii_ctrl

utf8::strip_ascii_ctrl() removes all ASCII control characters from a string.

Example:

echo utf8::strip_ascii_ctrl("a\0b".chr(7).'c');
// Output: abc

strip_non_ascii

utf8::strip_non_ascii() removes all non-ASCII characters from a string.

Example:

echo utf8::strip_non_ascii('Clichés');
// Output: Clichs

stristr

strlen

strpos

strrev

strrpos

strspn

strtolower

strtoupper

substr

substr_replace

to_unicode

transliterate_to_ascii

utf8::transliterate_to_ascii() replaces many (not all) special/accented characters by their ASCII equivalents. Special characters that are unknown to this method are left untouched. You can remove them afterwards with the strip_non_ascii method.

Example:

echo utf8::transliterate_to_ascii('Jérôme est un garçon.');
// Output: Jerome est un garcon.

Further reading: Wikipedia on transliteration

trim

ucfirst

ucwords

« Kohana : Previous