PHPackages                             sjaakp/yii2-helpers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sjaakp/yii2-helpers

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

sjaakp/yii2-helpers
===================

Various helpers for Yii2 PHP framework

1.1.0(6y ago)11971MITPHP

Since Mar 2Pushed 6y agoCompare

[ Source](https://github.com/sjaakp/yii2-helpers)[ Packagist](https://packagist.org/packages/sjaakp/yii2-helpers)[ RSS](/packages/sjaakp-yii2-helpers/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (1)Versions (3)Used By (1)

Yii2-helpers
============

[](#yii2-helpers)

This is a collection of various helpers for the [Yii 2.0](https://yiiframework.com/ "Yii") PHP Framework. All of them are abstract classes having only static functions in the `sjaakp\helpers` namespace.

Installation
------------

[](#installation)

The preferred way to install **yii2-helpers** is through [Composer](https://getcomposer.org/). Either add the following to the require section of your `composer.json` file:

`"sjaakp/yii2-helpers": "*"`

Or run:

`composer require sjaakp/yii2-helpers "*"`

You can manually install **yii2-helpers** by [downloading the source in ZIP-format](https://github.com/sjaakp/yii2-helpers/archive/master.zip).

Fragment
--------

[](#fragment)

Distill one or more relevant fragments from a string. A fragment is considered relevant if it contains a part that matches a regex pattern.

- **static function fragment($subject, $pattern, $radius = `50`, $affix = `'&hellip;'`, $highlightOptions = `[ ]`)**

    - $subject: `string`
    - $pattern: PHP [regex pattern](https://www.php.net/manual/en/reference.pcre.pattern.syntax.php).
    - $radius: `int` Tentative number of characters before and after match. Size of the fragments will be `2 * $radius`, plus the length of the matched part, if possible.
    - $affix: `string` Text before and after fragments, if appropriate.
    - $highlightOptions: `array|false` HTML options for the highlight tag. Key `'tag'` defines tag type; if not set, the tag type will be `'mark'`. If false, no highlighting occurs.
    - Return: `string`.
- **public static function phpPattern($lucenePattern)**Convert a [Zend Lucene query string](https://framework.zend.com/manual/1.12/en/zend.search.lucene.query-api.html)to an acceptable PHP query string.

Roman
-----

[](#roman)

Functions to convert an `int` into a [Roman numeral](https://en.wikipedia.org/wiki/Roman_numerals)vice versa.

- **static function toInt($roman)** Converts Roman numeral string `$roman`to `int`. Invalid `$roman` will be converted to `0`.
- **static function toRoman($int)** Converts `$int` to Roman numeral (`1
