This is documentation for Kohana v2.3.x.
Status | First Draft |
---|---|
Todo | Expand, fill in missing methods |
Provides static methods to work with UTF-8 strings as PHP is not yet natively capable of doing that.
Requirements:
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.
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)
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
utf8::strip_non_ascii()
removes all non-ASCII characters from a string.
Example:
echo utf8::strip_non_ascii('Clichés'); // Output: Clichs
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
« Kohana : Previous