|
5 лет назад | |
---|---|---|
.. | ||
src | 5 лет назад | |
CHANGELOG.md | 5 лет назад | |
LICENSE.txt | 5 лет назад | |
README.md | 5 лет назад | |
composer.json | 5 лет назад |
It is written in PHP (PHP 7+) and can work without "mbstring", "iconv" or any other extra encoding php-extension on your server.
The benefit of Portable ASCII is that it is easy to use, easy to bundle.
The project based on ...
If you like a more Object Oriented Way to edit strings, then you can take a look at voku/Stringy, it's a fork of "danielstjules/Stringy" but it used the "Portable ASCII"-Class and some extra methods.
// Portable ASCII
use voku\helper\ASCII;
ASCII::to_transliterate('déjà σσς iıii'); // 'deja sss iiii'
// voku/Stringy
use Stringy\Stringy as S;
$stringy = S::create('déjà σσς iıii');
$stringy->toTransliterate(); // 'deja sss iiii'
composer require voku/portable-ascii
I need ASCII char handling in different classes and before I added this functions into "Portable UTF-8", but this repo is more modular and portable, because it has no dependencies.
Example: ASCII::to_ascii()
echo ASCII::to_ascii('�Düsseldorf�', 'de');
// will output
// Duesseldorf
echo ASCII::to_ascii('�Düsseldorf�', 'en');
// will output
// Dusseldorf
The API from the "ASCII"-Class is written as small static methods.
Returns an replacement array for ASCII methods.
$array = ASCII::charsArray();
var_dump($array['ru']['б']); // 'b'
Returns an replacement array for ASCII methods with a mix of multiple languages.
$array = ASCII::charsArrayWithMultiLanguageValues();
var_dump($array['b']); // ['β', 'б', 'ဗ', 'ბ', 'ب']
Returns an replacement array for ASCII methods with one language.
For example, German will map 'ä' to 'ae', while other languages will simply return e.g. 'a'.
$array = ASCII::charsArrayWithOneLanguage('ru');
$tmpKey = \array_search('yo', $array['replace']);
echo $array['orig'][$tmpKey]; // 'ё'
Returns an replacement array for ASCII methods with multiple languages.
$array = ASCII::charsArrayWithSingleLanguageValues();
$tmpKey = \array_search('hnaik', $array['replace']);
echo $array['orig'][$tmpKey]; // '၌'
Checks if a string is 7 bit ASCII.
ASCII::is_ascii('白'); // false
Normalize some MS Word special characters.
ASCII::normalize_msword('„Abcdef…”'); // '"Abcdef..."'
Normalize the whitespace.
ASCII::normalize_whitespace("abc-\xc2\xa0-öäü-\xe2\x80\xaf-\xE2\x80\xAC", true); // "abc-\xc2\xa0-öäü- -"
Convert a string into language specific ASCII.
ASCII::to_ascii('�Düsseldorf�', 'en'); // Dusseldorf
Convert given string to safe filename (and keep string case).
ASCII::to_filename('שדגשדג.png', true)); // 'shdgshdg.png'
Convert a string into ASCII.
ASCII::to_transliterate('déjà σσς iıii'); // 'deja sss iiii'
1) Composer is a prerequisite for running the tests.
composer install
2) The tests can be executed by running this command from the root directory:
./vendor/bin/phpunit
For support and donations please visit Github | Issues | PayPal | Patreon.
For status updates and release announcements please visit Releases | Twitter | Patreon.
For professional support please contact me.
Released under the MIT License - see LICENSE.txt
for details.