mako\Charset


Description


Charset helper.


Class methods


Toggle source

protected __construct()


Protected constructor since this is a static class.

Return value

NULL

protected function __construct()
{
	// Nothing here
}

Toggle source

public static isAscii($str)


Check if a string only contains ascii characters.


Parameters

Type Description
string The input string
Return value

boolean

public static function isAscii($str)
{
	return ! preg_match('/[^\x00-\x7F]/', $str);
}

Toggle source

public static clean($str, $charset = 'UTF-8')


Silently remove all invalid characters.


Parameters

Type Description
string The input string
string (optional) Expected charset
Return value

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;
}

Toggle source

public static convert($str, $charset = 'UTF-8')


Converts a string to the chosen charset.


Parameters

Type Description
string String to convert
string (optional) Character set to convert to
Return value

string

public static function convert($str, $charset = MAKO_CHARSET)
{
	return mb_convert_encoding($str, $charset, mb_detect_encoding($str));
}