cse/helpers-word

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.

1.0.6 2019-04-28 08:58 UTC

This package is auto-updated.

Last update: 2024-11-29 05:39:11 UTC


README

English | Русский

WORD CSE HELPERS

Travis (.org) Codecov Scrutinizer code quality

Packagist Minimum PHP Version Packagist GitHub repo size

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) . ' '
);
// мурлычит двадцать один котик

Introduction

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:

Below you will find some information on how to init library and perform common commands.

Install

You can find the most recent version of this project here.

Composer

Execute the following command to get the latest version of the package:

composer require cse/helpers-word

Or file composer.json should include the following contents:

{
    "require": {
        "cse/helpers-word": "*"
    }
}

Git

Clone this repository locally:

git clone https://github.com/cs-eliseev/helpers-word.git

Download

Download the latest release here.

Usage

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 января 2019

Add delimiter to result:

Word::convertDateMonthToWord('05.05.2018', '/');
// 05/мая/2018

Inclination

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 online

Convert number to word

Example:

Word::convertUnsignedIntNumberToWord(0);
// ноль
Word::convertUnsignedIntNumberToWord('1001');
// одна тысяча один

Change ones inclination:

Word::convertUnsignedIntNumberToWord(2002, 0);
// две тысячи двe

Convert 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');
// ExampleWord

Revert CamelCase:

Word::camelCase('ExampleWord', true);
// example-word

Change delimiter:

Word::camelCase('ExampleWord', true, '/');
// example/word

Testing & Code Coverage

PHPUnit 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.xml

Donating

You 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.

License

The WORD CSE HELPERS is open-source PHP library licensed under the MIT license. Please see License File for more information.

GitHub @cs-eliseev