2017 © Pedro Peláez
 

library php_rutils

RUtils is a Russian-specific string utils (transliteration, numeral is words, russian dates, typography)

image

andre_487/php_rutils

RUtils is a Russian-specific string utils (transliteration, numeral is words, russian dates, typography)

  • Sunday, July 31, 2016
  • by Andre-487
  • Repository
  • 24 Watchers
  • 210 Stars
  • 39,796 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 45 Forks
  • 9 Open issues
  • 4 Versions
  • 21 % Grown

The README.md

PHP RUtils

Больше не поддерживается

Summary

License Latest Stable Version, (*1)

Build Status Code Climate, (*2)

RUtils is a Russian-specific string utils (transliteration, numeral is words, russian dates, typography) for PHP. This is a port of the Python Pytils to PHP., (*3)

See additional docs and examples in doc subdir., (*4)

Library is published on the Composer: https://packagist.org/packages/andre_487/php_rutils, (*5)


RUtils — утилиты для работы c текстом на русском языке (транслитерация, числительные словами, русские даты, простая типографика) для языка PHP. RUtils — порт утилит Pytils на PHP., (*6)

Документацию и примеры смотрите в каталоге doc., (*7)

Библиотека доступна через Composer: https://packagist.org/packages/andre_487/php_rutils, (*8)

Daily Downloads Monthly Downloads Total Downloads, (*9)


Буду рад принять помощь по проекту в виде советов, баг-репортов и pull-реквестов., (*10)

Проект следует стилю кодирования PSR-2. Стиль проверяется с помощью PHP_CodeSniffer на этапе CI., (*11)

Хочу сказать большое спасибо всем людям, внесшим свой вклад в улучшение проекта., (*12)


Basic usage

Modules of PHP RUtils: - Numeral - Plural forms and in-word representation for numerals - Dt - Russian dates without locales and other dates handling - Translit - Simple transliteration - Typo - Basic russian typography, (*13)

Numeral, (*14)

Choosing the word form depending of a number:, (*15)

$variants = array(
    'гвоздь', //1
    'гвоздя', //2
    'гвоздей' //5
);
echo $amount, ' ', RUtils::numeral()->choosePlural(15, $variants);
//Result: 15 гвоздей

echo RUtils::numeral()->getPlural(2, $variants);
//Result: 2 гвоздя

Choosing the word form and print number in words:, (*16)

echo RUtils::numeral()->sumString(1234, RUtils::MALE, $variants);
//Result: одна тысяча двести тридцать четыре гвоздя

Print number in words:, (*17)

$numeral = RUtils::numeral();
echo $numeral->getInWordsInt(100);
//Result: сто

echo $numeral->getInWordsFloat(100.025);
//Result: сто целых двадцать пять тысячных

echo $numeral->getInWords(100.0);
//Result: сто

Print money (RUB):, (*18)

echo RUtils::numeral()->getRubles(100.25);
//Result: сто рублей двадцать пять копеек

Dt, (*19)

Today date: \php_rutils\struct\TimeParams - params structure, may be passed as array, (*20)

$params = new TimeParams();
$params->date = null; //default value, 'now'
$params->format = 'сегодня d F Y года';
$params->monthInflected = true;
echo RUtils::dt()->ruStrFTime($params);
//Result: сегодня 22 октября 2013 года

Historical date:, (*21)

$params = array(
    'date' => '09-05-1945',
    'format' => 'l d F Y была одержана победа над немецко-фашистскими захватчиками',
    'monthInflected' => true,
    'preposition' => true,
);
echo RUtils::dt()->ruStrFTime($params);
//Result: в среду 9 мая 1945 была одержана победа над немецко-фашистскими захватчиками

Time interval to fixed date:, (*22)

$toTime = new \DateTime('05-06-1945'); //Unix timestamp and string also available
echo RUtils::dt()->distanceOfTimeInWords($toTime), PHP_EOL;
//Result: 68 лет назад

$toTime = strtotime('05-06-1945');
$fromTime = null; //now
$accuracy = RUtils::ACCURACY_MINUTE; //years, months, days, hours, minutes
echo RUtils::dt()->distanceOfTimeInWords($toTime, $fromTime, $accuracy), PHP_EOL;
//Result: 68 лет, 4 месяца, 21 день, 19 часов, 12 минут назад

Time interval from fixed date to fixed date:, (*23)

$fromTime = '1988-01-01 11:40';
$toTime = '2088-01-01 12:35';
$accuracy = RUtils::ACCURACY_MINUTE; //years, months, days, hours, minutes
echo RUtils::dt()->distanceOfTimeInWords($toTime, $fromTime, $accuracy), PHP_EOL;
//Result: через 100 лет, 55 минут

Age:, (*24)

$birthDate = strtotime('today - 25 years');
echo RUtils::dt()->getAge($birthDate);
//Result: 25

Translit, (*25)

//Translify
echo RUtils::translit()->translify('Муха - это маленькая птичка');
//Result: Muxa - e`to malen`kaya ptichka

//Detranslify
echo RUtils::translit()->detranslify("Muxa - e`to malen`kaya ptichka");
//Result: Муха - это маленькая птичка

//Prepare to use in URLs or file paths
echo RUtils::translit()->slugify('Муха — это маленькая птичка');
//Result: muha-eto-malenkaya-ptichka

Typo, (*26)

$text = <<<TEXT
...Когда В. И. Пупкин увидел в газете ( это была "Сермяжная правда" № 45) рубрику Weather Forecast (r),
он не поверил своим глазам - температуру обещали +-451F.
TEXT;

//Standard rules
echo RUtils::typo()->typography($text);
/**
 * Result:
 * ...Когда В. И. Пупкин увидел в газете (это была «Сермяжная правда» №45) рубрику Weather Forecast®,
 * он не поверил своим глазам — температуру обещали ±451°F.
 */


//Extended rules
echo RUtils::typo()->typography($text, TypoRules::$EXTENDED_RULES);
/**
 * Result:
 * …Когда В. И. Пупкин увидел в газете (это была «Сермяжная правда» №45) рубрику Weather Forecast®,
 * он не поверил своим глазам — температуру обещали ±451 °F.
 */

//Custom rules
echo RUtils::typo()->typography($text, array(TypoRules::DASHES, TypoRules::CLEAN_SPACES));
/**
 * Result:
 * ...Когда В. И. Пупкин увидел в газете (это была "Сермяжная правда" № 45) рубрику Weather Forecast (r),
 * он не поверил своим глазам — температуру обещали +-451F.
 */

The Versions

31/07 2016

dev-master

9999999-dev https://github.com/Andre-487/php_rutils

RUtils is a Russian-specific string utils (transliteration, numeral is words, russian dates, typography)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

typography transliteration numeral is words russian dates

24/10 2015

1.2.0

1.2.0.0 https://github.com/Andre-487/php_rutils

RUtils is a Russian-specific string utils (transliteration, numeral is words, russian dates, typography)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

typography transliteration numeral is words russian dates

19/11 2013

1.1.1

1.1.1.0 https://github.com/Andre-487/php_rutils

RUtils is a Russian-specific string utils (transliteration, numeral is words, russian dates, typography)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

typography transliteration numeral is words russian dates

26/10 2013

1.1.0

1.1.0.0 https://github.com/Andre-487/php_rutils

RUtils is a Russian-specific string utils (transliteration, numeral is words, russian dates, typography)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

typography transliteration numeral is words russian dates