当前位置: 首页>>代码示例>>PHP>>正文


PHP text::is_ascii方法代码示例

本文整理汇总了PHP中text::is_ascii方法的典型用法代码示例。如果您正苦于以下问题:PHP text::is_ascii方法的具体用法?PHP text::is_ascii怎么用?PHP text::is_ascii使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在text的用法示例。


在下文中一共展示了text::is_ascii方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: clean

 /**
  * Transliterate UTF8 text to lowercase 7bit ASCII, 0-9a-z
  *
  * @param   string  $str
  * @return  string
  */
 public static function clean($str)
 {
     $str = mb_strtolower(text::strip_ascii_ctrl($str));
     if (!text::is_ascii($str)) {
         $str = strtolower(text::transliterate_to_ascii($str));
     }
     if (!text::is_ascii($str)) {
         $str = text::strip_non_ascii($str);
     }
     return $str;
     // return strtolower(iconv(Kohana::CHARSET, 'ASCII//TRANSLIT//IGNORE', $str));
 }
开发者ID:anqqa,项目名称:Anqh,代码行数:18,代码来源:MY_utf8.php

示例2: is_ascii

 /**
  * Tests the text::is_ascii() function.
  * @dataProvider is_ascii_provider
  * @group core.helpers.text.is_ascii
  * @test
  */
 public function is_ascii($str, $expected_result)
 {
     $result = text::is_ascii($str);
     $this->assertEquals($expected_result, $result);
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:11,代码来源:Helper_Text_Test.php

示例3: 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 (text::is_ascii($charlist)) {
         return rtrim($str, $charlist);
     }
     $charlist = preg_replace('#[-\\[\\]:\\\\^/]#', '\\\\$0', $charlist);
     return preg_replace('/[' . $charlist . ']++$/uD', '', $str);
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:21,代码来源:utf8.php

示例4: 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 = text::strip_ascii_ctrl($str);
         if (!text::is_ascii($str)) {
             // Disable notices
             $ER = error_reporting(~E_NOTICE);
             // iconv is expensive, so it is only used when needed
             $str = iconv(Kohana::CHARSET, Kohana::CHARSET . '//IGNORE', $str);
             // Turn notices back on
             error_reporting($ER);
         }
     }
     return $str;
 }
开发者ID:assad2012,项目名称:gallery3-appfog,代码行数:29,代码来源:Input.php

示例5: 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  hexdec    hexadecimal characters, 0-9 plus a-f
  * @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 = FALSE;
     switch ($type) {
         case 'alnum':
             $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             break;
         case 'alpha':
             $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             break;
         case 'hexdec':
             $pool = '0123456789abcdef';
             break;
         case 'numeric':
             $pool = '0123456789';
             break;
         case 'nozero':
             $pool = '123456789';
             break;
         case 'distinct':
             $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ';
             break;
         default:
             $pool = (string) $type;
             $utf8 = !text::is_ascii($pool);
             break;
     }
     // Split the pool into an array of characters
     $pool = $utf8 === TRUE ? utf8::str_split($pool, 1) : str_split($pool, 1);
     // Largest pool key
     $max = count($pool) - 1;
     $str = '';
     for ($i = 0; $i < $length; $i++) {
         // Select a random character from the pool and add it to the string
         $str .= $pool[mt_rand(0, $max)];
     }
     // Make sure alnum strings contain at least one letter and one digit
     if ($type === 'alnum' and $length > 1) {
         if (ctype_alpha($str)) {
             // Add a random digit
             $str[mt_rand(0, $length - 1)] = chr(mt_rand(48, 57));
         } elseif (ctype_digit($str)) {
             // Add a random letter
             $str[mt_rand(0, $length - 1)] = chr(mt_rand(65, 90));
         }
     }
     return $str;
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:62,代码来源:text.php


注:本文中的text::is_ascii方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。