本文整理匯總了PHP中utf8::transliterate_to_ascii方法的典型用法代碼示例。如果您正苦於以下問題:PHP utf8::transliterate_to_ascii方法的具體用法?PHP utf8::transliterate_to_ascii怎麽用?PHP utf8::transliterate_to_ascii使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utf8
的用法示例。
在下文中一共展示了utf8::transliterate_to_ascii方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: title
/**
* Convert a phrase to a URL-safe title.
*
* @param string phrase to convert
* @param string word separator (- or _)
* @return string
*/
public static function title($title, $separator = '-')
{
$separator = $separator === '-' ? '-' : '_';
// Replace accented characters by their unaccented equivalents
$title = utf8::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));
// 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);
}