本文整理汇总了PHP中str::is_ascii方法的典型用法代码示例。如果您正苦于以下问题:PHP str::is_ascii方法的具体用法?PHP str::is_ascii怎么用?PHP str::is_ascii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::is_ascii方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rtrim
/**
* Strips whitespace (or other UTF-8 characters) from the end of a string.
* @see http://php.net/rtrim
*
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param string input string
* @param string string of characters to remove
* @return string
*/
public static function rtrim($str, $charlist = NULL)
{
if ($charlist === NULL) {
return rtrim($str);
}
if (str::is_ascii($charlist)) {
return rtrim($str, $charlist);
}
$charlist = preg_replace('#[-\\[\\]:\\\\^/]#', '\\\\$0', $charlist);
return preg_replace('/[' . $charlist . ']++$/uD', '', $str);
}
示例2: random
/**
* Generates a random string of a given type and length.
*
* @param string a type of pool, or a string of characters to use as the pool
* @param integer length of string to return
* @return string
*
* @tutorial alnum - alpha-numeric characters
* @tutorial alpha - alphabetical characters
* @tutorial numeric - digit characters, 0-9
* @tutorial nozero - digit characters, 1-9
* @tutorial distinct - clearly distinct alpha-numeric characters
*/
public static function random($type = 'alnum', $length = 8)
{
$utf8 = NO;
switch ($type) {
case 'alnum':
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alpha':
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'numeric':
$pool = '0123456789';
break;
case 'nozero':
$pool = '123456789';
break;
case 'distinct':
$pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
break;
default:
$pool = (string) $type;
$utf8 = !str::is_ascii($pool);
break;
}
$str = '';
$pool_size = $utf8 === YES ? mb_strlen($pool) : strlen($pool);
for ($i = 0; $i < $length; $i++) {
$str .= $utf8 === YES ? mb_substr($pool, mt_rand(0, $pool_size - 1), 1) : substr($pool, mt_rand(0, $pool_size - 1), 1);
}
return $str;
}
示例3: clean
/**
* Recursively cleans arrays, objects, and strings. Removes ASCII control
* codes and converts to UTF-8 while silently discarding incompatible
* UTF-8 characters.
*
* @param string string to clean
* @return string
*/
public static function clean($str)
{
if (is_array($str) or is_object($str)) {
foreach ($str as $key => $val) {
// Recursion!
$str[Input::clean($key)] = Input::clean($val);
}
} elseif (is_string($str) and $str !== '') {
// Remove control characters
$str = str::strip_ascii_ctrl($str);
if (!str::is_ascii($str)) {
// Disable notices
$ER = error_reporting(~E_NOTICE);
// iconv is expensive, so it is only used when needed
$str = iconv(Eight::CHARSET, Eight::CHARSET . '//IGNORE', $str);
// Turn notices back on
error_reporting($ER);
}
}
return $str;
}