Charset helper.
Protected constructor since this is a static class.
NULL
protected function __construct()
{
// Nothing here
}
Check if a string only contains ascii characters.
| Type | Description |
|---|---|
| string | The input string |
boolean
public static function isAscii($str)
{
return ! preg_match('/[^\x00-\x7F]/', $str);
}
Silently remove all invalid characters.
| Type | Description |
|---|---|
| string | The input string |
| string | (optional) Expected charset |
string
public static function clean($str, $charset = MAKO_CHARSET)
{
$error = error_reporting(~E_NOTICE);
$str = iconv($charset, $charset . '//IGNORE', $str);
error_reporting($error);
return $str;
}
Converts a string to the chosen charset.
| Type | Description |
|---|---|
| string | String to convert |
| string | (optional) Character set to convert to |
string
public static function convert($str, $charset = MAKO_CHARSET)
{
return mb_convert_encoding($str, $charset, mb_detect_encoding($str));
}