Transliterator::transliterate

transliterator_transliterate

(No version information available, might only be in SVN)

Transliterator::transliterate -- transliterator_transliterateTransliterate a string

Description

Oriented object style

public void Transliterator::transliterate ( string $subject [, string $start [, string $end ]] )

Procedural style

transliterator_transliterate ( string $subject [, string $start [, string $end ]] )

Transliterates a string.

Warning

This function is currently not documented; only its argument list is available.

Parameters

subject

The string to be transliterated.

start

end

Return Values

The transliterated string on success, or FALSE on failure.

See Also

add a note add a note

User Contributed Notes 3 notes

up
6
simonsimcity at gmail dot com
1 year ago
I pretty much like the idea of hdogan, but there's at least one group of characters he's missing: ligature characters.
They're at least used in Norwegian and I read something about French, too ... Some are just used for styling (f.e. fi)

Here's an example that supports all characters (should at least, according to the documentation):
<?php
var_dump
(transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', "A æ Übérmensch på høyeste nivå! И я люблю PHP! fi"));
// string(41) "a ae ubermensch pa hoyeste niva! i a lublu php! fi"
?>

In this example any character will firstly be converted to a latin character. If that's finished, replace all latin characters by their ASCII replacement.
up
5
hdogan at gmail dot com
1 year ago
You can create slugs easily with:

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

echo
slugify("Я люблю PHP!");
?>
up
1
jinmoku at hotmail dot com
3 years ago
OOP version :

<?php
$str
= 'àáâãäçèéêëìíîïñòóôõöùúûüýÿ
ÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'
;
$rule = 'NFD; [:Nonspacing Mark:] Remove; NFC';

$myTrans = Transliterator::create($rule);
echo
$myTrans->transliterate($str);
 
//aaaaaceeeeiiiinooooouuuuyy
//AAAAACEEEEIIIINOOOOOUUUUY
?>
To Top