The charset helper contains methods that can be useful when working with character sets.
The isAscii method returns TRUE if a string contains only ASCII characters and false if not.
$isAscii = Charset::isAscii('Hello, world!'); // True
$isAscii = Charset::isAscii('Hellø, world!'); // False
The clean method will silently remove all invalid characters from a string.
// Will return a string containing only characters from the default charset of your application $clean = Charset::clean($string); // Will return a string containing only ISO-8859-1 characters $clean = Charset::clean($string, 'ISO-8859-1');
The convert method will convert a string to the chosen charset.
// Will convert the string to the default charset of your application $clean = Charset::convert($string); // Will convert the string to ISO-8859-1 $clean = Charset::convert($string, 'ISO-8859-1');