Charset helper


Description


The charset helper contains methods that can be useful when working with character sets.


Methods


isAscii(string $str)


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

clean(string $str, string $charset = MAKO_CHARSET)


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');

convert(string $str, string $charset = MAKO_CHARSET)


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');