T
T
tigra2016-06-27 18:30:26
PHP
tigra, 2016-06-27 18:30:26

How to use Transliterator?

There is a need to transliterate the string. Connected the INTL module. And how to use this miracle.
It is elementary to translate the line
$str = "Hello everyone";
php.net/manual/ru/class.transliterator.php
I didn't understand anything in the documentation.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cat Anton, 2016-06-27
@tigroid3

function slugify($string) {
    $translit = "Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();";
    $string = transliterator_transliterate($translit, $string);
    $string = preg_replace('/[-\s]+/', '-', $string);
    return trim($string, '-');
}

echo slugify("Я люблю PHP!");

Source: php.net/manual/ru/transliterator.transliterate.php...

V
Vasiliskov, 2017-02-24
@Vasiliskov

A simplified version, without lighting up the docks by transliteration:

transliterator_transliterate('Latin-ASCII', transliterator_transliterate('Latin', $sourceString));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question