本文整理汇总了PHP中transliterator_transliterate函数的典型用法代码示例。如果您正苦于以下问题:PHP transliterator_transliterate函数的具体用法?PHP transliterator_transliterate怎么用?PHP transliterator_transliterate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了transliterator_transliterate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ersin-demirtas,项目名称:EasySlugger,代码行数:13,代码来源:Utf8Slugger.php
示例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;
}
开发者ID:basuritas-php,项目名称:php-slugger,代码行数:13,代码来源:Utf8Slugger.php
示例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;
}
开发者ID:gpis88ce,项目名称:Gpis88ce,代码行数:22,代码来源:LittleBigHelper.php
示例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;
}
开发者ID:John-Eddy,项目名称:ProjetCastor,代码行数:22,代码来源:Transliterator.php
示例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;
}
开发者ID:myurasov,项目名称:mym-mongodb-odm-tools,代码行数:8,代码来源:ReadableIdTrait.php
示例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);
}
开发者ID:zwq,项目名称:yii2_restful,代码行数:9,代码来源:Internet.php
示例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);
}
开发者ID:africc,项目名称:php-epp2,代码行数:9,代码来源:Translit.php
示例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);
}
开发者ID:Umz,项目名称:ImpressPages,代码行数:11,代码来源:Transliteration.php
示例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);
}
开发者ID:kjmtrue,项目名称:phalcon-tip,代码行数:19,代码来源:Slug.php
示例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;
}
开发者ID:webvimark,项目名称:helpers,代码行数:23,代码来源:LittleBigHelper.php
示例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';
}
开发者ID:blab2015,项目名称:seh,代码行数:17,代码来源:ServicesToStringTransformer.php
示例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);
}
开发者ID:websharks,项目名称:core,代码行数:24,代码来源:Transliterate.php
示例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;
}
开发者ID:winponta,项目名称:helpers,代码行数:16,代码来源:StringHelper.php
示例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;
}
开发者ID:webowy,项目名称:zend-filter,代码行数:22,代码来源:Normalize.php
示例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;
}
开发者ID:jacquesmattheij,项目名称:SRS,代码行数:19,代码来源:learn.php
示例16: translitRename
/**
* Filename translitaration renamin
* @param \Iphp\FileStoreBundle\Mapping\PropertyMapping $propertyMapping
* @param $name
* @return string
*/
public function translitRename(PropertyMapping $propertyMapping, $name)
{
if (function_exists('transliterator_transliterate')) {
$name = transliterator_transliterate("Any-Latin; Latin-ASCII; [\\u0100-\\u7fff] remove", $name);
$name = preg_replace('/[^\\pL\\d.]+/u', '-', $name);
$name = preg_replace('/[-\\s]+/', '-', $name);
} else {
$iso = array("Є" => "YE", "І" => "I", "Ѓ" => "G", "і" => "i", "№" => "N", "є" => "ye", "ѓ" => "g", "А" => "A", "Б" => "B", "В" => "V", "Г" => "G", "Д" => "D", "Е" => "E", "Ё" => "e", "Ж" => "z", "З" => "Z", "И" => "I", "Й" => "J", "К" => "K", "Л" => "L", "М" => "M", "Н" => "N", "О" => "O", "П" => "P", "Р" => "R", "С" => "S", "Т" => "T", "У" => "U", "Ф" => "F", "Х" => "H", "Ц" => "C", "Ч" => "C", "Ш" => "S", "Щ" => "s", "Ъ" => "", "Ы" => "Y", "Ь" => "", "Э" => "E", "Ю" => "U", "Я" => "a", "а" => "a", "б" => "b", "в" => "v", "г" => "g", "д" => "d", "е" => "e", "ё" => "e", "ж" => "z", "з" => "z", "и" => "i", "й" => "j", "к" => "k", "л" => "l", "м" => "m", "н" => "n", "о" => "o", "п" => "p", "р" => "r", "с" => "s", "т" => "t", "у" => "u", "ф" => "f", "х" => "h", "ц" => "c", "ч" => "c", "ш" => "s", "щ" => "s", "ъ" => "", "ы" => "y", "ь" => "", "э" => "e", "ю" => "u", "я" => "a", "«" => "", "»" => "", "—" => "-");
$name = strtr($name, $iso);
$name = preg_replace('/[^\\pL\\d.]+/u', '-', $name);
$name = preg_replace('/[-\\s]+/', '-', $name);
// transliterate
if (function_exists('iconv')) {
$name = iconv('utf-8', 'ASCII//TRANSLIT//IGNORE', $name);
}
$name = preg_replace("/[^0-9A-Za-z-_ .]/", "", $name);
}
$name = trim($name, '-');
$name = strtolower($name);
return $name;
}
开发者ID:fatihkahveci,项目名称:IphpFileStoreBundle,代码行数:27,代码来源:DefaultNamer.php
示例17: slugify
/**
* warning requires `yum -y install php-intl`
* for transliterator to work
* @param $text
*
* @return mixed|string
*/
public static function slugify($text)
{
static $transliteratorExists;
if (empty($text)) {
return 'n-a';
}
if (is_null($transliteratorExists)) {
$transliteratorExists = function_exists('transliterator_transliterate') && ($transliterator = \Transliterator::create("Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC; Lower();") !== null);
}
if ($transliteratorExists === true) {
return preg_replace('#[ -]+#', '-', transliterator_transliterate('Any-Latin; Latin-ASCII; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();', $text));
}
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\\d]+~u', '-', $text);
$text = trim($text, '-');
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
$text = strtolower($text);
$text = preg_replace('~[^-\\w]+~', '', $text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
开发者ID:bellostom,项目名称:php-edge,代码行数:30,代码来源:Utils.php
示例18: cleanFileName
private function cleanFileName($originalName)
{
$transliteratedName = transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $originalName);
$strippedName = preg_replace('/[^\\da-z.\\-\\s]+/', '', $transliteratedName);
return trim(preg_replace('/[-\\s]+/', '-', $strippedName));
}
开发者ID:norzechowicz,项目名称:doctrine-extensions,代码行数:6,代码来源:TransliterateEntity.php
示例19: utf8_latin_to_ascii
public static function utf8_latin_to_ascii($subject)
{
static $CHARS = NULL;
if (is_null($CHARS)) {
$CHARS = array('À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'ß' => 's', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ý' => 'y', 'ÿ' => 'y', 'Ā' => 'A', 'ā' => 'a', 'Ă' => 'A', 'ă' => 'a', 'Ą' => 'A', 'ą' => 'a', 'Ć' => 'C', 'ć' => 'c', 'Ĉ' => 'C', 'ĉ' => 'c', 'Ċ' => 'C', 'ċ' => 'c', 'Č' => 'C', 'č' => 'c', 'Ď' => 'D', 'ď' => 'd', 'Đ' => 'D', 'đ' => 'd', 'Ē' => 'E', 'ē' => 'e', 'Ĕ' => 'E', 'ĕ' => 'e', 'Ė' => 'E', 'ė' => 'e', 'Ę' => 'E', 'ę' => 'e', 'Ě' => 'E', 'ě' => 'e', 'Ĝ' => 'G', 'ĝ' => 'g', 'Ğ' => 'G', 'ğ' => 'g', 'Ġ' => 'G', 'ġ' => 'g', 'Ģ' => 'G', 'ģ' => 'g', 'Ĥ' => 'H', 'ĥ' => 'h', 'Ħ' => 'H', 'ħ' => 'h', 'Ĩ' => 'I', 'ĩ' => 'i', 'Ī' => 'I', 'ī' => 'i', 'Ĭ' => 'I', 'ĭ' => 'i', 'Į' => 'I', 'į' => 'i', 'İ' => 'I', 'ı' => 'i', 'IJ' => 'IJ', 'ij' => 'ij', 'Ĵ' => 'J', 'ĵ' => 'j', 'Ķ' => 'K', 'ķ' => 'k', 'Ĺ' => 'L', 'ĺ' => 'l', 'Ļ' => 'L', 'ļ' => 'l', 'Ľ' => 'L', 'ľ' => 'l', 'Ŀ' => 'L', 'ŀ' => 'l', 'Ł' => 'l', 'ł' => 'l', 'Ń' => 'N', 'ń' => 'n', 'Ņ' => 'N', 'ņ' => 'n', 'Ň' => 'N', 'ň' => 'n', 'ʼn' => 'n', 'Ō' => 'O', 'ō' => 'o', 'Ŏ' => 'O', 'ŏ' => 'o', 'Ő' => 'O', 'ő' => 'o', 'Œ' => 'OE', 'œ' => 'oe', 'Ŕ' => 'R', 'ŕ' => 'r', 'Ŗ' => 'R', 'ŗ' => 'r', 'Ř' => 'R', 'ř' => 'r', 'Ś' => 'S', 'ś' => 's', 'Ŝ' => 'S', 'ŝ' => 's', 'Ş' => 'S', 'ş' => 's', 'Š' => 'S', 'š' => 's', 'Ţ' => 'T', 'ţ' => 't', 'Ť' => 'T', 'ť' => 't', 'Ŧ' => 'T', 'ŧ' => 't', 'Ũ' => 'U', 'ũ' => 'u', 'Ū' => 'U', 'ū' => 'u', 'Ŭ' => 'U', 'ŭ' => 'u', 'Ů' => 'U', 'ů' => 'u', 'Ű' => 'U', 'ű' => 'u', 'Ų' => 'U', 'ų' => 'u', 'Ŵ' => 'W', 'ŵ' => 'w', 'Ŷ' => 'Y', 'ŷ' => 'y', 'Ÿ' => 'Y', 'Ź' => 'Z', 'ź' => 'z', 'Ż' => 'Z', 'ż' => 'z', 'Ž' => 'Z', 'ž' => 'z', 'ſ' => 's', 'ƒ' => 'f', 'Ơ' => 'O', 'ơ' => 'o', 'Ư' => 'U', 'ư' => 'u', 'Ǎ' => 'A', 'ǎ' => 'a', 'Ǐ' => 'I', 'ǐ' => 'i', 'Ǒ' => 'O', 'ǒ' => 'o', 'Ǔ' => 'U', 'ǔ' => 'u', 'Ǖ' => 'U', 'ǖ' => 'u', 'Ǘ' => 'U', 'ǘ' => 'u', 'Ǚ' => 'U', 'ǚ' => 'u', 'Ǜ' => 'U', 'ǜ' => 'u', 'Ǻ' => 'A', 'ǻ' => 'a', 'Ǽ' => 'AE', 'ǽ' => 'ae', 'Ǿ' => 'O', 'ǿ' => 'o');
}
if (function_exists('transliterator_transliterate')) {
if (is_array($subject)) {
array_walk($subject, function (&$string) {
$string = WFUtility::utf8_latin_to_ascii($string);
});
return $subject;
}
$transformed = transliterator_transliterate('Any-Latin; Latin-ASCII;', $subject);
if ($transformed !== false) {
return $transformed;
}
return str_replace(array_keys($CHARS), array_values($CHARS), $subject);
}
return str_replace(array_keys($CHARS), array_values($CHARS), $subject);
}
开发者ID:cuongnd,项目名称:etravelservice,代码行数:21,代码来源:utility.php
示例20: fix_filename
/**
* Cleanup filename
*
* @param string $str
* @param bool $transliteration
* @param bool $convert_spaces
* @param string $replace_with
* @param bool $is_folder
*
* @return string
*/
function fix_filename($str, $transliteration, $convert_spaces = false, $replace_with = "_", $is_folder = false)
{
if ($convert_spaces) {
$str = str_replace(' ', $replace_with, $str);
}
if ($transliteration) {
if (!mb_detect_encoding($str, 'UTF-8', true)) {
$str = utf8_encode($str);
}
if (function_exists('transliterator_transliterate')) {
$str = transliterator_transliterate('Any-Latin; Latin-ASCII', $str);
} else {
$str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
}
$str = preg_replace("/[^a-zA-Z0-9\\.\\[\\]_| -]/", '', $str);
}
$str = str_replace(array('"', "'", "/", "\\"), "", $str);
$str = strip_tags($str);
// Empty or incorrectly transliterated filename.
// Here is a point: a good file UNKNOWN_LANGUAGE.jpg could become .jpg in previous code.
// So we add that default 'file' name to fix that issue.
if (strpos($str, '.') === 0 && $is_folder === false) {
$str = 'file' . $str;
}
return trim($str);
}
开发者ID:fznoviar,项目名称:responsivefilemanager,代码行数:37,代码来源:utils.php
注:本文中的transliterator_transliterate函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论