本文整理汇总了PHP中text::transliterate_to_ascii方法的典型用法代码示例。如果您正苦于以下问题:PHP text::transliterate_to_ascii方法的具体用法?PHP text::transliterate_to_ascii怎么用?PHP text::transliterate_to_ascii使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类text
的用法示例。
在下文中一共展示了text::transliterate_to_ascii方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例2: transliterate_to_ascii
/**
* 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: convert_filename_to_slug
/**
* 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: title
/**
* 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);
}