本文整理汇总了PHP中transliterator_transliterate函数的典型用法代码示例。如果您正苦于以下问题:PHP transliterator_transliterate函数的具体用法?PHP transliterator_transliterate怎么用?PHP transliterator_transliterate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了transliterator_transliterate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: slugify
/**
* {@inheritdoc}
*/
public static function slugify($string, $separator = null)
{
$separator = null !== $separator ? $separator : (null !== self::$separator ? self::$separator : '-');
$slug = trim(strip_tags($string));
$slug = transliterator_transliterate('NFD; [:Nonspacing Mark:] Remove; NFC; Any-Latin; Latin-ASCII; Lower();', $slug);
$slug = preg_replace("/[^a-zA-Z0-9\\/_|+ -]/", '', $slug);
$slug = preg_replace("/[\\/_|+ -]+/", $separator, $slug);
$slug = trim($slug, $separator);
return $slug;
}
示例2: slugify
/**
* {@inheritdoc}
*/
public function slugify($string, $separator = null)
{
$separator = $separator ?: $this->separator;
$slug = trim(strip_tags($string));
$slug = transliterator_transliterate("NFD; [:Nonspacing Mark:] Remove; NFC; Any-Latin; Latin-ASCII; Lower();", $slug);
$slug = preg_replace("/[^a-zA-Z0-9\\/_|+ -]/", '', $slug);
$slug = preg_replace("/[\\/_|+ -]+/", $separator, $slug);
$slug = trim($slug, $separator);
return $slug;
}
示例3: slug
/**
* Return old good slug
*
* @param string $string
* @param string $replacement
* @param bool $lowercase
*
* @return string
*/
public static function slug($string, $replacement = '-', $lowercase = true)
{
if (extension_loaded('intl') === true) {
$options = 'Any-Latin; NFKD; [:Punctuation:] Remove; [^\\u0000-\\u007E] Remove';
$string = transliterator_transliterate($options, $string);
$string = preg_replace('/[-=\\s]+/', $replacement, $string);
} else {
$string = str_replace(array_keys(static::$transliteration), static::$transliteration, $string);
$string = preg_replace('/[^\\p{L}\\p{Nd}]+/u', $replacement, $string);
}
$string = trim($string, $replacement);
return $lowercase ? strtolower($string) : $string;
}
示例4: transliterate
public static function transliterate($string)
{
// needs intl extension
if (function_exists('transliterator_transliterate')) {
$string = transliterator_transliterate("Any-Latin; Latin-ASCII; [\\u0100-\\u7fff] remove", $string);
$string = preg_replace('/[^\\pL\\d._]+/u', '-', $string);
$string = preg_replace('/[-\\s]+/', '-', $string);
} else {
// uses iconv
$string = preg_replace('~[^\\pL0-9_\\.]+~u', '-', $string);
// substitutes anything but letters, numbers and '-' with separator
$string = trim($string, '-');
if (function_exists('iconv')) {
$string = iconv('utf-8', 'us-ascii//TRANSLIT', $string);
// TRANSLIT does the whole job
}
$string = preg_replace('~[^-a-zA-Z0-9_\\.]+~', '', $string);
// keep only letters, numbers, '_' and separator
}
$string = trim($string, '-');
return $string;
}
示例5: formatReadableId
protected function formatReadableId($id)
{
$id = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $id);
$id = preg_replace('/([^a-z0-9])/iu', '-', $id);
$id = preg_replace('/-+/u', '-', $id);
$id = trim($id, '-');
return $id;
}
示例6: transliterate
private static function transliterate($string)
{
if (function_exists('transliterator_transliterate')) {
$transString = transliterator_transliterate("Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC; Lower();", $string);
} else {
$transString = static::toAscii($string);
}
return preg_replace('/[^A-Za-z0-9_.]/u', '', $transString);
}
示例7: transliterate
public static function transliterate($string)
{
// the reason for using this rather "exotic" function in contrary to
// iconv is, that iconv is very unstable. It relies on the correct
// linked library, which means it works different on OSX than on Linux
// also iconv + setlocale is not thread safe, so if you are using IIS
// php-fpm, fastcgi or similar it can/will break
return transliterator_transliterate('Any-Latin; Latin-ASCII; [\\u0100-\\u7fff] remove', $string);
}
示例8: transform
public static function transform($string)
{
if (!function_exists('transliterator_transliterate') || !function_exists('transliterator_list_ids')) {
return self::simpleTransform($string);
}
$transliteratorIds = transliterator_list_ids();
if (!in_array('Any-Latin', $transliteratorIds) || !in_array('Latin-ASCII', $transliteratorIds)) {
return self::simpleTransform($string);
}
return transliterator_transliterate('Any-Latin; Latin-ASCII; [\\u0100-\\u7fff] remove', $string);
}
示例9: generate
/**
* Creates a slug to be used for pretty URLs
*
* @param $string
* @param string $delimiter
* @return string
*/
public static function generate($string, $delimiter = '-')
{
if (function_exists('transliterator_transliterate')) {
$string = transliterator_transliterate('Any-Latin; Latin-ASCII; [:Punctuation:] Remove; Lower()', $string);
} else {
$string = mb_strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $string));
}
$string = preg_replace('/[-\\s]+/', $delimiter, $string);
$string = preg_replace('/^[-\\s]+/', '', $string);
$string = preg_replace('/[-\\s]+$/', '', $string);
return trim($string, $delimiter);
}
示例10: slug
/**
* Return old good slug
*
* @param string $string
* @param string $replacement
* @param bool $lowercase
*
* @return string
*/
public static function slug($string, $replacement = '-', $lowercase = true)
{
if (extension_loaded('intl') === true) {
$options = 'Any-Latin; NFKD';
$string = transliterator_transliterate($options, $string);
$string = preg_replace('/[^a-zA-Z0-9=\\s—–-]+/u', '', $string);
$string = preg_replace('/[=\\s—–-]+/u', $replacement, $string);
} else {
$string = str_replace(array_keys(static::$transliteration), static::$transliteration, $string);
$string = preg_replace('/[^\\p{L}\\p{Nd}]+/u', $replacement, $string);
}
$string = trim($string, $replacement);
return $lowercase ? strtolower($string) : $string;
}
示例11: transformForSeo
/**
* {@inheritDoc}
*/
public function transformForSeo($services = null)
{
if (null == $services) {
return "";
}
if (!($services instanceof \ArrayAccess or is_array($services) or $services instanceof \Traversable or $services instanceof \Countable)) {
throw new \InvalidArgumentException('The given argument must be array accessible');
}
$servicesSlug = array();
foreach ($services as $service) {
$servicesSlug[] = str_replace(' ', '', transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $service->getName()));
}
return count($servicesSlug) ? implode('+', $servicesSlug) : 'noservices';
}
示例12: toAscii
/**
* Convert to ASCII.
*
* @since 150424 Multibyte support.
*
* @param mixed $value Any input value.
*
* @return string|array|object Output value.
*/
public function toAscii($value)
{
if (is_array($value) || is_object($value)) {
foreach ($value as $_key => &$_value) {
$_value = $this->toAscii($_value);
}
// unset($_key, $_value);
return $value;
}
if (!($string = (string) $value)) {
return $string;
// Nothing to do.
}
return (string) transliterator_transliterate('Any-Latin; Latin-ASCII', $string);
}
示例13: transliterate
public static function transliterate($string, $options = ['UPPER'])
{
$op = '';
if (array_key_exists('UPPER', $options) || in_array('UPPER', $options)) {
$op = '; Upper()';
}
if (array_key_exists('LOWER', $options) || in_array('LOWER', $options)) {
$op = '; Lower()';
}
//$string = mb_convert_case($string, MB_CASE_UPPER, "UTF-8");
$string = transliterator_transliterate('Any-Latin; Latin-ASCII; [\\u0100-\\u7fff] remove' . $op, $string);
$string = trim($string);
// TODO verify if we should remove -
//$string = str_replace('-','',$string);
return $string;
}
示例14: filter
/**
* @param mixed $value
* @param string $replaceChar
* @return string
*/
public function filter($value, $replaceChar = '-')
{
// Setting en_US locale to replace diacritic characters.
setlocale(LC_CTYPE, 'en_US.UTF-8');
// Do not filter non-string values
if (!is_string($value)) {
return $value;
}
$string = str_replace(array('&', '&'), 'and', $value);
$string = transliterator_transliterate('Any-Latin;Latin-ASCII;', $string);
$string = @iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$string = preg_replace('/[^a-z0-9]+/i', $replaceChar, $string);
$string = preg_replace('/\\_+/', $replaceChar, $string);
$string = trim($string, $replaceChar);
$string = strtolower($string);
return $string;
}
示例15: strip_diacriticals
function strip_diacriticals($in)
{
if (function_exists('transliterator_transliterate')) {
// PHP 5.4 + intl
return transliterator_transliterate('Any-Latin; Latin-ASCII', $in);
}
if (function_exists('normalizer_normalize')) {
// PHP 5.3 + intl
return normalizer_normalize(preg_replace('/\\p{Mn}+/u', '', normalizer_normalize($in, Normalizer::FORM_D)), Normalizer::FORM_C);
}
if (function_exists('iconv') && ICONV_IMPL == 'glibc') {
return iconv('UTF-8', 'ASCII//TRANSLIT', $in);
}
// version incomplète (limitée au latin1)
$patterns = array('~&([A-za-z])(?:grave|acute|circ|tilde|uml|ring|cedil|slash|caron);~' => '\\1', '~&([A-za-z]{2})lig;~' => '\\1', '~&[^;]+;~' => '');
$out = htmlentities($in, ENT_NOQUOTES, 'UTF-8');
$out = preg_replace(array_keys($patterns), array_values($patterns), $out);
return $out;
}