示例#1
0
文件: MY_utf8.php 项目: anqqa/Anqh
 /**
  * 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));
 }
 /**
  * Tests the text::strip_ascii_ctrl() function.
  * @dataProvider strip_ascii_ctrl_provider
  * @group core.helpers.text.strip_ascii_ctrl
  * @test
  */
 public function strip_ascii_ctrl($str, $expected_result)
 {
     $result = text::strip_ascii_ctrl($str);
     $this->assertEquals($expected_result, $result);
 }
示例#3
0
 /**
  * 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;
 }