Language-specific conversion
The language argument of to_ascii() selects the mapping. The same input gives different output per language.
<?php use voku\helper\ASCII; echo ASCII::to_ascii('Düsseldorf', 'de'); // Duesseldorfecho ASCII::to_ascii('Düsseldorf', 'en'); // Dusseldorf
Extra symbols
With $replace_extra_symbols set to true, symbols such as £ are spelled out. The signature is to_ascii($str, $language, $remove_unsupported_chars, $replace_extra_symbols, ...).
<?php use voku\helper\ASCII; echo ASCII::to_ascii('Price: £5', 'en', true, true); // "Price: pound 5"echo ASCII::to_slugify('test © test', '-', 'en', [], true); // test-c-test
Slugs with a custom separator and replacements
<?php use voku\helper\ASCII; echo ASCII::to_slugify('Hello World', '_'); // hello_worldecho ASCII::to_slugify('Hello World', '.'); // hello.worldecho ASCII::to_slugify('CamelCase', '_', 'en', [], false, false); // Camel_Caseecho ASCII::to_slugify('Tom & Jerry', '-', 'en', ['&' => 'and']); // tom-and-jerry
Transliteration with unknown characters
<?php use voku\helper\ASCII; echo ASCII::to_transliterate('déjà σσς iıii'); // deja sss iiiiecho ASCII::to_transliterate('こんにちは'); // konnichiha
Clean user input
clean() removes malformed UTF-8 and, by default, normalizes whitespace and MS Word characters and removes invisible characters.
<?php use voku\helper\ASCII; $input = "a\xC2\xA0b…\xff"; // non-breaking space, ellipsis, invalid byte echo ASCII::clean($input); // "a b..."echo ASCII::normalize_msword('„Abcdef…”'); // '"Abcdef..."'echo ASCII::remove_invisible_characters("Java\0script"); // Javascript
Look up the character maps
<?php use voku\helper\ASCII; $array = ASCII::charsArray();var_dump($array['ru']['б']); // 'b' $multi = ASCII::charsArrayWithMultiLanguageValues();var_dump($multi['b']); // ['б', 'բ', 'ဗ', 'ბ', 'ب', 'ব'] $languages = ASCII::getAllLanguages(); // ['uzbek' => 'uz', 'turkmen' => 'tk', ...]