Transliterator::create
transliterator_create
(PHP >= 5.4.0, PECL intl >= 2.0.0)
Transliterator::create -- transliterator_create — Create a transliterator
Description
Object oriented style
Procedural style
Opens a Transliterator by id.
Warning
This function is currently not documented; only its argument list is available.
Parameters
-
id
-
The id.
-
direction
-
The direction, defaults to >Transliterator::FORWARD. May also be set to Transliterator::REVERSE.
Return Values
Returns a Transliterator object on success,
or NULL
on failure.
See Also
- Transliterator::getErrorMessage() - Get last error message
- Transliterator::__construct() - Private constructor to deny instantiation
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Поддержка языков и кодировок
- Internationalization Functions
- Функция Transliterator::__construct() - Private constructor to deny instantiation
- Функция Transliterator::create() - Create a transliterator
- Функция Transliterator::createFromRules() - Create transliterator from rules
- Функция Transliterator::createInverse() - Create an inverse transliterator
- Функция Transliterator::getErrorCode() - Get last error code
- Функция Transliterator::getErrorMessage() - Get last error message
- Функция Transliterator::listIDs() - Get transliterator IDs
- Функция Transliterator::transliterate() - Transliterate a string
Коментарии
A good example of create for non latin languages is Turkish.
There both upper case I character and lowercase ı character which makes other strtolower kind of functions useless.
$text = "Iğdır";
echo Transliterator::create("tr-Lower")->transliterate($text);
will return the correct result ığdır, not iğdır .
If you want to go deeper into what is going on, read the ICU projects docs: http://userguide.icu-project.org/transforms/general
This API call is basically just wrapper around ICU Transliteration.
// Translit each and every char to ASCII
$string = 'Москва́';
$string = Transliterator::create('Any-Latin; Latin-ASCII')->transliterate($string);
print $string;
// the result is "Moskva"