示例#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::transliterate_to_ascii() function.
  * @dataProvider transliterate_to_ascii_provider
  * @group core.helpers.text.transliterate_to_ascii
  * @test
  */
 public function transliterate_to_ascii($str, $case, $expected_result)
 {
     $result = text::transliterate_to_ascii($str, $case);
     $this->assertEquals($expected_result, $result);
 }
示例#3
0
文件: item.php 项目: qboy1987/mooiyou
 /**
  * Convert a filename into something we can use as a url component.
  * @param string $filename
  */
 static function convert_filename_to_slug($filename)
 {
     $result = str_replace("&", "-and-", $filename);
     $result = str_replace(" ", "-", $result);
     // It's not easy to extend the text helper since it's called by the Input class which is
     // referenced in hooks/init_gallery, so it's
     if (class_exists("transliterate")) {
         $result = transliterate::utf8_to_ascii($result);
     } else {
         $result = text::transliterate_to_ascii($result);
     }
     $result = preg_replace("/[^A-Za-z0-9-_]+/", "-", $result);
     $result = preg_replace("/-+/", "-", $result);
     return trim($result, "-");
 }
示例#4
0
 /**
  * Convert a phrase to a URL-safe title.
  *
  * @param   string  phrase to convert
  * @param   string  word separator (- or _)
  * @param   boolean  transliterate to ASCII
  * @return  string
  */
 public static function title($title, $separator = '-', $ascii_only = FALSE)
 {
     $separator = $separator === '-' ? '-' : '_';
     if ($ascii_only === TRUE) {
         // Replace accented characters by their unaccented equivalents
         $title = text::transliterate_to_ascii($title);
         // Remove all characters that are not the separator, a-z, 0-9, or whitespace
         $title = preg_replace('/[^' . $separator . 'a-z0-9\\s]+/', '', strtolower($title));
     } else {
         // Remove all characters that are not the separator, letters, numbers, or whitespace
         $title = preg_replace('/[^' . $separator . '\\pL\\pN\\s]+/u', '', mb_strtolower($title));
     }
     // Replace all separator characters and whitespace by a single separator
     $title = preg_replace('/[' . $separator . '\\s]+/', $separator, $title);
     // Trim separators from the beginning and end
     return trim($title, $separator);
 }