PHPackages                             kolyunya/string-processor - 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. kolyunya/string-processor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kolyunya/string-processor
=========================

PHP string processing library.

1.0.0(9y ago)35.7kGNU GPL v3.0PHPPHP &gt;=5.3 &lt;8.0

Since Apr 20Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Kolyunya/string-processor)[ Packagist](https://packagist.org/packages/kolyunya/string-processor)[ Docs](https://github.com/Kolyunya/string-processor)[ RSS](/packages/kolyunya-string-processor/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

PHP string processing library
=============================

[](#php-string-processing-library)

Status
------

[](#status)

[![Build Status](https://camo.githubusercontent.com/5b7f08f5d5b6296d5e8172a62a5107836172ab4c1d4cbb611a189ddce3627c8a/68747470733a2f2f7472617669732d63692e6f72672f4b6f6c79756e79612f737472696e672d70726f636573736f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Kolyunya/string-processor)[![Code Climate](https://camo.githubusercontent.com/95f0b14e894990395368f59472eeeacdb24a762f8caae88a48e1434d4c990c63/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4b6f6c79756e79612f737472696e672d70726f636573736f722f6261646765732f6770612e737667)](https://codeclimate.com/github/Kolyunya/string-processor)[![Latest Stable Version](https://camo.githubusercontent.com/405318595d60ccc32482c360255ea4dd67342e8b37efe8101cf68667f30867c2/68747470733a2f2f706f7365722e707567782e6f72672f6b6f6c79756e79612f737472696e672d70726f636573736f722f762f737461626c65)](https://packagist.org/packages/kolyunya/string-processor)

Description
-----------

[](#description)

This library provides a collection of string processors.

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

[](#installation)

This library is [composer-enabled](https://packagist.org/packages/kolyunya/string-processor). The recommended way of using it in your project is to require it via `composer`.

```
composer require kolyunya/string-processor

```

Single processor usage
----------------------

[](#single-processor-usage)

### Basic usage

[](#basic-usage)

Each processor implements the [ProcessorInterface](https://github.com/Kolyunya/string-processor/blob/master/sources/ProcessorInterface.php) which contains the `process` method:

```
/**
 * Processes a string and returns a processed version of the original string.
 * @param string $string A string to process.
 * @return string A processed version of the original string.
 */
public function process($string);
```

Construct a processor and run `process($string)` on it:

```
$processor = new Processor();
echo $processor->process($string);
```

### Shorthand usage

[](#shorthand-usage)

You can also use a processor without even instantiating it. Each processor has a static `run` method.

```
/**
 * Processes a string and returns a processed version of the original string.
 * @param string $string A string to process.
 * @param object|array $parameters Parameters passed to the processor's constructor.
 * @return string A processed version of the original string.
 */
public static function run($string, $parameters = array());
```

You can pass parameters to the processor's constructor in the `$parameters` array. You can also pass a single parameter without wrapping it into an array.

```
echo KebabCaseFormatter::run('snake_case'); // Output: "snake-case"
echo Translator::run(
    'Лорем ипсум долор сит амет',
    new RuEnDictionary()
); // Output: "Lorem ipsum dolor sit amet"
```

Processors combination
----------------------

[](#processors-combination)

### `Multiprocessor` usage

[](#multiprocessor-usage)

There is a special processor ([`Multiprocessor`](https://github.com/Kolyunya/string-processor/blob/master/sources/Multiprocessor.php)) which allows you to combine multiple processors in one. Suppose you want to convert a string to an `UPPER-KEBAB` case. You can combine two processors using `Multiprocessor` to solve this problem.

```
$processor = new Multiprocessor([
    new KebabCaseFormatter(),
    new UpperCaseFormatter(),
]);
echo $processor->process('snake_case'); // Output: "SNAKE-CASE"
echo $processor->process('CamelCase'); // Output: "CAMEL-CASE"
```

The `UpperCaseFormatter` will be applied after the `KebabCaseFormatter`. Note that either the processors order does not matter in the first example, it actually matters in the second one.

Another common problem example is to generate URL slugs. A string should be purified from punctuation characters, converted to the `kebab-case` and transliterated. Combine the `PunctuationStripper`, the `KebabCaseFormatter` and the `Translator` using `Multiprocessor`.

```
$processor = new Multiprocessor([
    new RuEnTranslator(),
    new AlphabeticalPurifier(),
    new KebabCaseFormatter(),
]);
echo $processor->process('Лорем ипсум долор сит амет'); // Output: "lorem-ipsum-dolor-sit-amet"
echo $processor->process('Привет, Мир!'); // Output: "privet-mir"
```

### Processors decoration

[](#processors-decoration)

Each processor is a [decorator](https://en.wikipedia.org/wiki/Decorator_pattern). The [ProcessorInterface](https://github.com/Kolyunya/string-processor/blob/master/sources/ProcessorInterface.php) contains the `decorate` method:

```
/**
 * Decorates supplied processor with the current processor.
 * @param ProcessorInterface $processor Processor to decorate.
 * @return ProcessorInterface Current processor.
 */
public function decorate(ProcessorInterface $processor);
```

That means that the above example can be implemented using processors decoration. The `Multiprocessor` usage is somewhat more readable though.

```
$processor =
(new RuEnTranslator())->decorate(
    (new KebabCaseFormatter())->decorate(
        (new PunctuationStripper())
    )
);
echo $processor->process('Лорем ипсум долор сит амет'); // Output: "lorem-ipsum-dolor-sit-amet"
echo $processor->process('Привет, Мир!'); // Output: "privet-mir"
```

Available processors
--------------------

[](#available-processors)

Currently the following processors are implemented:

- [Case switchers](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/CaseSwitcher.php) - format strings to arbitrary formats.
    - [CamelCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/CamelCaseFormatter.php) - formats a string to the `CamelCase`.
    - [KebabCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/KebabCaseFormatter.php) - formats a string to the `kebab-case`.
    - [SnakeCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/SnakeCaseFormatter.php) - formats a string to the `snake_case`.
    - [UpperCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/UpperCaseFormatter.php) - formats a string to the `UPPER CASE`.
    - [LowerCaseFormatter](https://github.com/Kolyunya/string-processor/blob/master/sources/Format/LowerCaseFormatter.php) - formats a string to the `lower case`.
- [Translators](https://github.com/Kolyunya/string-processor/blob/master/sources/Translit/Translator.php) - transliterate strings from one language to another.
    - [RuEnTranslator](https://github.com/Kolyunya/string-processor/blob/master/sources/Translit/RuEnTranslator.php) - transliterates strings from Russian to English and the other way around.
- [Purifiers](https://github.com/Kolyunya/string-processor/blob/master/sources/Purify/BasePurifier.php) - purify strings.
    - [PunctuationStripper](https://github.com/Kolyunya/string-processor/blob/master/sources/Purify/PunctuationStripper.php) - Strips punctuation characters.
    - [AlphabeticalPurifier](https://github.com/Kolyunya/string-processor/blob/master/sources/Purify/AlphabeticalPurifier.php) - Strips non-alphabetical characters.
- [Multiprocessor](https://github.com/Kolyunya/string-processor/blob/master/sources/Multiprocessor.php) - combines multiple processors.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3351d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2682768?v=4)[Nick Oleynikov](/maintainers/Kolyunya)[@Kolyunya](https://github.com/Kolyunya)

---

Top Contributors

[![Kolyunya](https://avatars.githubusercontent.com/u/2682768?v=4)](https://github.com/Kolyunya "Kolyunya (84 commits)")

---

Tags

camel-casekebab-casesnake-casestringstring-manipulationstring-parsingstring-processingstringstring manipulationcamel casekebab casesnake casestring-processingstring-parsing

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/kolyunya-string-processor/health.svg)

```
[![Health](https://phpackages.com/badges/kolyunya-string-processor/health.svg)](https://phpackages.com/packages/kolyunya-string-processor)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k417.9M1.7k](/packages/nette-utils)[jawira/case-converter

Convert strings between 13 naming conventions: Snake case, Camel case, Pascal case, Kebab case, Ada case, Train case, Cobol case, Macro case, Upper case, Lower case, Sentence case, Title case and Dot notation.

1747.5M86](/packages/jawira-case-converter)[opis/string

Multibyte strings as objects

7424.5M8](/packages/opis-string)[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4265.3M23](/packages/kwn-number-to-words)[coduo/php-to-string

Simple library that converts PHP value into strings

26913.1M13](/packages/coduo-php-to-string)[icecave/repr

A library for generating string representations of any value, inspired by Python's reprlib library.

277.5M4](/packages/icecave-repr)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
