本文整理汇总了PHP中UTF8::strip_ascii_ctrl方法的典型用法代码示例。如果您正苦于以下问题:PHP UTF8::strip_ascii_ctrl方法的具体用法?PHP UTF8::strip_ascii_ctrl怎么用?PHP UTF8::strip_ascii_ctrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8
的用法示例。
在下文中一共展示了UTF8::strip_ascii_ctrl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clean
public static function clean($var, $charset = NULL)
{
if (!$charset) {
// Use the application character set
$charset = JsonApiApplication::$charset;
}
if (is_array($var) or is_object($var)) {
foreach ($var as $key => $val) {
// Recursion!
$var[UTF8::clean($key)] = UTF8::clean($val);
}
} elseif (is_string($var) and $var !== "") {
// Remove control characters
$var = UTF8::strip_ascii_ctrl($var);
if (!UTF8::is_ascii($var)) {
// Temporarily save the mb_substitute_character() value into a variable
$mb_substitute_character = mb_substitute_character();
// Disable substituting illegal characters with the default '?' character
mb_substitute_character("none");
// convert encoding, this is expensive, used when $var is not ASCII
$var = mb_convert_encoding($var, $charset, $charset);
// Reset mb_substitute_character() value back to the original setting
mb_substitute_character($mb_substitute_character);
}
}
return $var;
}
示例2: clean
/**
* Recursively cleans arrays, objects, and strings. Removes ASCII control
* codes and converts to the requested charset while silently discarding
* incompatible characters.
*
* @param mixed $str
* @return string
*/
public static function clean($str)
{
if (is_array($str) || is_object($str)) {
foreach ($str as $key => $val) {
$str[$key] = self::clean($val);
}
} else {
if (is_string($str) && $str !== '') {
$str = mb_strtolower(UTF8::strip_ascii_ctrl($str));
if (!UTF8::is_ascii($str)) {
$str = strtolower(self::transliterate_to_ascii($str));
}
if (!UTF8::is_ascii($str)) {
$str = UTF8::strip_non_ascii($str);
}
}
}
return $str;
}
示例3: clean
/**
* Recursively cleans arrays, objects, and strings. Removes ASCII control
* codes and converts to the requested charset while silently discarding
* incompatible characters.
*
* UTF8::clean($_GET); // Clean GET data
*
* @param mixed $var variable to clean
* @param string $charset character set, defaults to Kohana::$charset
* @return mixed
* @uses UTF8::clean
* @uses UTF8::strip_ascii_ctrl
* @uses UTF8::is_ascii
*/
public static function clean($var, $charset = 'utf-8')
{
if (is_array($var) or is_object($var)) {
foreach ($var as $key => $val) {
// Recursion!
$var[UTF8::clean($key)] = UTF8::clean($val);
}
} elseif (is_string($var) and $var !== '') {
// Remove control characters
$var = UTF8::strip_ascii_ctrl($var);
if (!UTF8::is_ascii($var)) {
// Disable notices
$error_reporting = error_reporting(~E_NOTICE);
$var = mb_convert_encoding($var, $charset, $charset);
// Turn notices back on
error_reporting($error_reporting);
}
}
return $var;
}
示例4: test_strip_ascii_ctrl
/**
* Tests UTF8::strip_ascii_ctrl
*
* @test
* @dataProvider provider_strip_ascii_ctrl
*/
public function test_strip_ascii_ctrl($input, $expected)
{
$this->assertSame($expected, UTF8::strip_ascii_ctrl($input));
}