本文整理汇总了PHP中UTF8::is_ascii方法的典型用法代码示例。如果您正苦于以下问题:PHP UTF8::is_ascii方法的具体用法?PHP UTF8::is_ascii怎么用?PHP UTF8::is_ascii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8
的用法示例。
在下文中一共展示了UTF8::is_ascii方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: _str_pad
/**
* UTF8::str_pad
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
if (UTF8::is_ascii($str) and UTF8::is_ascii($pad_str)) {
return str_pad($str, $final_str_length, $pad_str, $pad_type);
}
$str_length = UTF8::strlen($str);
if ($final_str_length <= 0 or $final_str_length <= $str_length) {
return $str;
}
$pad_str_length = UTF8::strlen($pad_str);
$pad_length = $final_str_length - $str_length;
if ($pad_type == STR_PAD_RIGHT) {
$repeat = ceil($pad_length / $pad_str_length);
return UTF8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
}
if ($pad_type == STR_PAD_LEFT) {
$repeat = ceil($pad_length / $pad_str_length);
return UTF8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
}
if ($pad_type == STR_PAD_BOTH) {
$pad_length /= 2;
$pad_length_left = floor($pad_length);
$pad_length_right = ceil($pad_length);
$repeat_left = ceil($pad_length_left / $pad_str_length);
$repeat_right = ceil($pad_length_right / $pad_str_length);
$pad_left = UTF8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
$pad_right = UTF8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_right);
return $pad_left . $str . $pad_right;
}
throw new UTF8_Exception("UTF8::str_pad: Unknown padding type (:pad_type)", [':pad_type' => $pad_type]);
}
示例3: _strlen
/**
* UTF8::strlen
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _strlen($str)
{
if (UTF8::is_ascii($str)) {
return strlen($str);
}
return strlen(utf8_decode($str));
}
示例4: _str_pad
/**
* UTF8::str_pad
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2010 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
if (UTF8::is_ascii($str) and UTF8::is_ascii($pad_str)) {
return str_pad($str, $final_str_length, $pad_str, $pad_type);
}
$str_length = UTF8::strlen($str);
if ($final_str_length <= 0 or $final_str_length <= $str_length) {
return $str;
}
$pad_str_length = UTF8::strlen($pad_str);
$pad_length = $final_str_length - $str_length;
if ($pad_type == STR_PAD_RIGHT) {
$repeat = ceil($pad_length / $pad_str_length);
return UTF8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
}
if ($pad_type == STR_PAD_LEFT) {
$repeat = ceil($pad_length / $pad_str_length);
return UTF8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
}
if ($pad_type == STR_PAD_BOTH) {
$pad_length /= 2;
$pad_length_left = floor($pad_length);
$pad_length_right = ceil($pad_length);
$repeat_left = ceil($pad_length_left / $pad_str_length);
$repeat_right = ceil($pad_length_right / $pad_str_length);
$pad_left = UTF8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
$pad_right = UTF8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_right);
return $pad_left . $str . $pad_right;
}
trigger_error('UTF8::str_pad: Unknown padding type (' . $pad_type . ')', E_USER_ERROR);
}
示例5: _str_ireplace
/**
* UTF8::str_ireplace
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2010 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _str_ireplace($search, $replace, $str, & $count = NULL)
{
if (UTF8::is_ascii($search) AND UTF8::is_ascii($replace) AND UTF8::is_ascii($str))
return str_ireplace($search, $replace, $str, $count);
if (is_array($str))
{
foreach ($str as $key => $val)
{
$str[$key] = UTF8::str_ireplace($search, $replace, $val, $count);
}
return $str;
}
if (is_array($search))
{
$keys = array_keys($search);
foreach ($keys as $k)
{
if (is_array($replace))
{
if (array_key_exists($k, $replace))
{
$str = UTF8::str_ireplace($search[$k], $replace[$k], $str, $count);
}
else
{
$str = UTF8::str_ireplace($search[$k], '', $str, $count);
}
}
else
{
$str = UTF8::str_ireplace($search[$k], $replace, $str, $count);
}
}
return $str;
}
$search = UTF8::strtolower($search);
$str_lower = UTF8::strtolower($str);
$total_matched_strlen = 0;
$i = 0;
while (preg_match('/(.*?)'.preg_quote($search, '/').'/s', $str_lower, $matches))
{
$matched_strlen = strlen($matches[0]);
$str_lower = substr($str_lower, $matched_strlen);
$offset = $total_matched_strlen + strlen($matches[1]) + ($i * (strlen($replace) - 1));
$str = substr_replace($str, $replace, $offset, strlen($search));
$total_matched_strlen += $matched_strlen;
$i++;
}
$count += $i;
return $str;
}
示例6: _strrev
/**
* UTF8::strrev
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2011 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _strrev($str)
{
if (UTF8::is_ascii($str)) {
return strrev($str);
}
preg_match_all('/./us', $str, $matches);
return implode('', array_reverse($matches[0]));
}
示例7: _ucfirst
/**
* UTF8::ucfirst
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _ucfirst($str)
{
if (UTF8::is_ascii($str)) {
return ucfirst($str);
}
preg_match('/^(.?)(.*)$/us', $str, $matches);
return UTF8::strtoupper($matches[1]) . $matches[2];
}
示例8: site
public static function site($uri = '', $protocol = NULL, $index = TRUE)
{
$path = preg_replace('~^[-a-z0-9+.]++://[^/]++/?~', '', trim($uri, '/'));
if (!UTF8::is_ascii($path)) {
$path = preg_replace_callback('~([^/]+)~', 'URL::_rawurlencode_callback', $path);
}
return URL::base($protocol, $index) . $path;
}
示例9: _strcasecmp
/**
* UTF8::strcasecmp
*
* @package JsonApiApplication
* @author JsonApiApplication Team
* @copyright (c) 2007-2012 JsonApiApplication Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _strcasecmp($str1, $str2)
{
if (UTF8::is_ascii($str1) and UTF8::is_ascii($str2)) {
return strcasecmp($str1, $str2);
}
$str1 = UTF8::strtolower($str1);
$str2 = UTF8::strtolower($str2);
return strcmp($str1, $str2);
}
示例10: _ucwords
/**
* UTF8::ucwords
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _ucwords($str)
{
if (UTF8::is_ascii($str)) {
return ucwords($str);
}
// [\x0c\x09\x0b\x0a\x0d\x20] matches form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns.
// This corresponds to the definition of a 'word' defined at http://php.net/ucwords
return preg_replace('/(?<=^|[\\x0c\\x09\\x0b\\x0a\\x0d\\x20])[^\\x0c\\x09\\x0b\\x0a\\x0d\\x20]/ue', 'UTF8::strtoupper(\'$0\')', $str);
}
示例11: site
/**
* Fetches an absolute site URL based on a URI segment.
*
* echo URL::site('foo/bar');
*
* @param string $uri Site URI to convert
* @param mixed $protocol Protocol string or [Request] class to use protocol from
* @param boolean $index Include the index_page in the URL
* @return string
* @uses URL::base
*/
public static function site($uri = '', $protocol = NULL, $index = TRUE)
{
// Chop off possible scheme, host, port, user and pass parts
$path = preg_replace('~^[-a-z0-9+.]++://[^/]++/?~', '', trim($uri, '/'));
if (!UTF8::is_ascii($path)) {
// Encode all non-ASCII characters, as per RFC 1738
$path = preg_replace('~([^/]+)~e', 'rawurlencode("$1")', $path);
}
// Concat the URL
return URL::base($protocol, $index) . $path;
}
示例12: _ltrim
/**
* UTF8::ltrim
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _ltrim($str, $charlist = null)
{
if ($charlist === null) {
return ltrim($str);
}
if (UTF8::is_ascii($charlist)) {
return ltrim($str, $charlist);
}
$charlist = preg_replace('#[-\\[\\]:\\\\^/]#', '\\\\$0', $charlist);
return preg_replace('/^[' . $charlist . ']+/u', '', $str);
}
示例13: _rtrim
/**
* UTF8::rtrim
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _rtrim($str, $charlist = NULL)
{
if ($charlist === NULL) {
return rtrim($str);
}
if (UTF8::is_ascii($charlist)) {
return rtrim($str, $charlist);
}
$charlist = preg_replace('#[-\\[\\]:\\\\^/]#', '\\\\$0', $charlist);
return preg_replace('/[' . $charlist . ']++$/uD', '', $str);
}
示例14: _substr_replace
/**
* UTF8::substr_replace
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2012 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _substr_replace($str, $replacement, $offset, $length = null)
{
if (UTF8::is_ascii($str)) {
return $length === null ? substr_replace($str, $replacement, $offset) : substr_replace($str, $replacement, $offset, $length);
}
$length = $length === null ? UTF8::strlen($str) : (int) $length;
preg_match_all('/./us', $str, $str_array);
preg_match_all('/./us', $replacement, $replacement_array);
array_splice($str_array[0], $offset, $length, $replacement_array[0]);
return implode('', $str_array[0]);
}
示例15: _ltrim
/**
* UTF8::ltrim
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2007-2010 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _ltrim($str, $charlist = NULL)
{
if ($charlist === NULL)
return ltrim($str);
if (UTF8::is_ascii($charlist))
return ltrim($str, $charlist);
$charlist = preg_replace('#[-\[\]:\\\\^/]#', '\\\\$0', $charlist);
return preg_replace('/^['.$charlist.']+/u', '', $str);
}