English | Русский
The helpers allows you to modify string data. Inclination, transliterate, convert month date and convert number or amount to word - all this is available in this library.
Project repository: https://github.com/cs-eliseev/helpers-word
DEMO
$number = 21;
Word::getInclinationByNumber(
$number,
['котик', 'котика', 'котиков'],
'мурлычит ' . Word::convertUnsignedIntNumberToWord($number) . ' '
);
// мурлычит двадцать один котикCSE HELPERS is a collection of several libraries with simple functions written in PHP for people.
Despite using PHP as the main programming language for the Internet, its functions are not enough. WORD CSE HELPERS solves the problem: word inclination, word transliteration, number or sum conversion to a word, etc.
CSE HELPERS was created for the rapid development of web applications.
CSE Helpers project:
- Array CSE helpers
- Cookie CSE helpers
- Date CSE helpers
- Email CSE helpers
- IP CSE helpers
- Json CSE helpers
- Math Converter CSE helpers
- Phone CSE helpers
- Request CSE helpers
- Session CSE helpers
- Word CSE helpers
Below you will find some information on how to init library and perform common commands.
You can find the most recent version of this project here.
Execute the following command to get the latest version of the package:
composer require cse/helpers-wordOr file composer.json should include the following contents:
{
"require": {
"cse/helpers-word": "*"
}
}Clone this repository locally:
git clone https://github.com/cs-eliseev/helpers-word.gitDownload the latest release here.
The class consists of static methods that are conveniently used in any project. See example examples-word.php.
Convert string to UTF-8
Example default charset(CP1251):
$text = mb_convert_encoding('привет', 'CP1251');
Word::stringToUtf($text);
// приветSet charset:
$text = mb_convert_encoding('привет', 'KOI8-R');
Word::stringToUtf($text, 'KOI8-R');
// приветDate month to word converter
Example:
Word::convertDateMonthToWord('2019-01-01');
// 01 января 2019Add delimiter to result:
Word::convertDateMonthToWord('05.05.2018', '/');
// 05/мая/2018Inclination
Example:
Word::getInclinationByNumber(10, ['котик', 'котика', 'котиков']);
// котиковAdd number:
Word::getInclinationByNumber(0, ['%d котик', '%d котика', '%d котиков']);
// 0 котиковAdd string number to text:
Word::getInclinationByNumber('01', ['был %d котик', 'было %d котика', 'было %d котиков']);
// был 1 котикAdd text prefix:
Word::getInclinationByNumber(4, ['котик', 'котика', 'котиков'], 'еще %d ');
// еще 4 котикаText transliterate
Example:
Word::transliterate('12 пользователей online');
// 12 polzovateley onlineConvert number to word
Example:
Word::convertUnsignedIntNumberToWord(0);
// ноль
Word::convertUnsignedIntNumberToWord('1001');
// одна тысяча одинChange ones inclination:
Word::convertUnsignedIntNumberToWord(2002, 0);
// две тысячи двeConvert amount to word
Example:
Word::convertAmountToWord(0);
// ноль рублей 0 копеекCents example:
Word::convertAmountToWord('1001.1');
// одна тысяча один рубль 10 копеек
Word::convertAmountToWord(2012.01);
// две тысячи двенадцать рублей 01 копейкаCents to word example:
Word::convertAmountToWord(87654.02, true, true);
// восемьдесят семь тысяч шестьсот пятьдесят четыре рубля две копейкиIgnore zero cents:
Word::convertAmountToWord('1098765.00', false);
// один миллион девяносто восемь тысяч семьсот шестьдесят пять рублейCamelCase converter
Example:
Word::camelCase('example-word');
// ExampleWordRevert CamelCase:
Word::camelCase('ExampleWord', true);
// example-wordChange delimiter:
Word::camelCase('ExampleWord', true, '/');
// example/wordPHPUnit is used for unit testing. Unit tests ensure that class and methods does exactly what it is meant to do.
General PHPUnit documentation can be found at https://phpunit.de/documentation.html.
To run the PHPUnit unit tests, execute:
phpunit PATH/TO/PROJECT/tests/If you want code coverage reports, use the following:
phpunit --coverage-html ./report PATH/TO/PROJECT/tests/Used PHPUnit default config:
phpunit --configuration PATH/TO/PROJECT/phpunit.xmlYou can support this project here. You can also help out by contributing to the project, or reporting bugs. Even voicing your suggestions for features is great. Anything to help is much appreciated.
The WORD CSE HELPERS is open-source PHP library licensed under the MIT license. Please see License File for more information.
GitHub @cs-eliseev