PHPackages                             hoa-math-community/ustring - 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. [Search &amp; Filtering](/categories/search)
4. /
5. hoa-math-community/ustring

ActiveLibrary[Search &amp; Filtering](/categories/search)

hoa-math-community/ustring
==========================

The Hoa\\Ustring library.

v5.0.1(1y ago)01.1k↓25%1BSD-3-ClausePHPPHP ~8.0

Since Sep 16Pushed 1y agoCompare

[ Source](https://github.com/hoa-math-community/Ustring)[ Packagist](https://packagist.org/packages/hoa-math-community/ustring)[ RSS](/packages/hoa-math-community-ustring/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (18)Used By (1)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/a74d01787cd04d119ed1238528dda0c3a76b51fcc7b0ecc7550005e5175892c3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f75737472696e672f6d61737465722e737667)](https://travis-ci.org/hoaproject/ustring) [![Code coverage](https://camo.githubusercontent.com/47d1b705e893aee0280d8fbd8b5a734978a895fb9ff8a8ea5367d98a4ff0300d/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f75737472696e672f6d61737465722e737667)](https://coveralls.io/github/hoaproject/ustring?branch=master) [![Packagist](https://camo.githubusercontent.com/a5d67a0cb53585c8e2cd81b7dd83f0fbf9f8b98d49811a0283fb443f97a9bb7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f75737472696e672e737667)](https://packagist.org/packages/hoa/ustring) [![License](https://camo.githubusercontent.com/7d60153449acd002454a6b1335436ded7aecddf8d961091c8acd0974ae60beb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f75737472696e672e737667)](https://hoa-project.net/LICENSE)

 Hoa is a **modular**, **extensible** and **structured** set of PHP libraries.
 Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\\Ustring
============

[](#hoaustring)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Ustring)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/ustring)

This library allows to manipulate UTF-8 strings easily with some search algorithms.

[Learn more](https://central.hoa-project.net/Documentation/Library/Ustring).

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

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/ustring`](https://packagist.org/packages/hoa/ustring):

```
$ composer require hoa/ustring '~4.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

Before running the test suites, the development dependencies must be installed:

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

We propose a quick overview of two usages: manipulate UTF-8 strings and one search algorithm.

### Natural UTF-8 strings manipulation

[](#natural-utf-8-strings-manipulation)

The `Hoa\Ustring\Ustring` class allows to manipulate easily UTF-8 strings in a very natural way. This class implements the `\ArrayAccess`, `\Countable` and `\IteratorAggregate` interfaces. We will use the following examples:

```
$french   = new Hoa\Ustring\Ustring('Je t\'aime');
$arabic   = new Hoa\Ustring\Ustring('أحبك');
$japanese = new Hoa\Ustring\Ustring('私はあなたを愛して');
```

To get the first character, we will do:

```
var_dump(
    $french[0],  // string(1) "J"
    $arabic[0],  // string(2) "أ"
    $japanese[0] // string(3) "私"
);
```

And to get the last character, we will do `[-1]`. It supports unbounded (and modulo) indexes.

We note that it cares about text **direction**. Look at `$arabic[0]`, it returns `أ` and not `ك`. To get the direction, we can use the `Hoa\Ustring\Ustring::getDirection` method (which call the `Hoa\Ustring\Ustring::getCharDirection` static method), it returns either `Hoa\Ustring\Ustring::LTR` (`0`) or `Hoa\Ustring\Ustring::RTL` (`1`):

```
var_dump(
    $french->getDirection(),  // int(0)
    $arabic->getDirection(),  // int(1)
    $japanese->getDirection() // int(0)
);
```

Text direction is also important for the `append`, `prepend`, `pad`… methods on `Hoa\Ustring\Ustring` for example.

To get the length of a string, we can use the `count` function:

```
var_dump(
    count($french),  // int(9)
    count($arabic),  // int(4)
    count($japanese) // int(9)
);
```

We are also able to iterate over the string:

```
foreach ($arabic as $letter) {
    var_dump($letter);
}

/**
 * Will output:
 *     string(2) "أ"
 *     string(2) "ح"
 *     string(2) "ب"
 *     string(2) "ك"
 */
```

Again, text direction is useful here. For `$arabic`, the iteration is done from right to left.

Some static methods are helpful, such as `fromCode`, `toCode` or `isUtf8` on `Hoa\Ustring\Ustring`:

```
var_dump(
    Hoa\Ustring\Ustring::fromCode(0x1a9), // string(2) "Ʃ"
    Hoa\Ustring\Ustring::toCode('Ʃ'),     // int(425) == 0x1a9
    Hoa\Ustring\Ustring::isUtf8('Ʃ')      // bool(true)
);
```

We can also transform any text into ASCII:

```
$emoji = new Hoa\Ustring\Ustring('I ❤ Unicode');
$maths = new Hoa\Ustring\Ustring('∀ i ∈ ℕ');

echo
    $emoji->toAscii(), "\n",
    $maths->toAscii(), "\n";

/**
 * Will output:
 *     I (heavy black heart) Unicode
 *     (for all) i (element of) N
 */
```

### Search algorithm

[](#search-algorithm)

The `Hoa\Ustring\Search` implements search algorithms on strings.

For example, the `Hoa\Ustring\Search::approximated` method make a search by approximated patterns (with *k* differences based upon the principle diagonal monotony). If we search the word `GATAA` in `CAGATAAGAGAA` with 1 difference, we will do:

```
$search = Hoa\Ustring\Search::approximated(
    $haystack = 'CAGATAAGAGAA',
    $needle   = 'GATAA',
    $k        = 1
);
$solutions = array();

foreach ($search as $pos) {
    $solutions[] = substr($haystack, $pos['i'], $pos['l']);
}
```

We will found `AGATA`, `GATAA`, `ATAAG` and `GAGAA`.

The result is not very handy but the algorithm is much optimized and found many applications.

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\Ustring`](https://central.hoa-project.net/Documentation/Library/Ustring) contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

```
$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open
```

More documentation can be found on the project's website: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance46

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 93.3% 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

Every ~256 days

Recently: every ~856 days

Total

16

Last Release

416d ago

Major Versions

1.14.09.16 → 2.14.09.162014-09-17

2.15.03.25 → 3.15.05.292015-05-29

3.15.11.09 → 4.16.01.112016-01-11

4.17.01.16 → v5.0.02022-12-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/14144958f1893ddd81dafbd4df8583e38792ccc089462e3cb14b80eeba32cef3?d=identicon)[hubipe](/maintainers/hubipe)

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (154 commits)")[![hubipe](https://avatars.githubusercontent.com/u/617880?v=4)](https://github.com/hubipe "hubipe (2 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (2 commits)")[![boast](https://avatars.githubusercontent.com/u/51127?v=4)](https://github.com/boast "boast (1 commits)")[![nicolas-grekas](https://avatars.githubusercontent.com/u/243674?v=4)](https://github.com/nicolas-grekas "nicolas-grekas (1 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (1 commits)")[![stephpy](https://avatars.githubusercontent.com/u/232744?v=4)](https://github.com/stephpy "stephpy (1 commits)")[![k-nenad](https://avatars.githubusercontent.com/u/1924166?v=4)](https://github.com/k-nenad "k-nenad (1 commits)")[![flug](https://avatars.githubusercontent.com/u/1810304?v=4)](https://github.com/flug "flug (1 commits)")[![jubianchi](https://avatars.githubusercontent.com/u/327237?v=4)](https://github.com/jubianchi "jubianchi (1 commits)")

---

Tags

searchstringunicodelibrary

### Embed Badge

![Health badge](/badges/hoa-math-community-ustring/health.svg)

```
[![Health](https://phpackages.com/badges/hoa-math-community-ustring/health.svg)](https://phpackages.com/packages/hoa-math-community-ustring)
```

###  Alternatives

[ilya/fuzzy

Nice PHP library for fuzzy string searching

4298.7k](/packages/ilya-fuzzy)[smile/module-elasticsuite-cms-search

Smile Elasticsuite - Cms Pages Search Module for Smile Elasticsuite.

25916.7k1](/packages/smile-module-elasticsuite-cms-search)[bvdputte/kirby-bettersearch

A search plugin for Kirby (v3+ that searches for full word combinations rather than just individual words.

233.5k](/packages/bvdputte-kirby-bettersearch)

PHPackages © 2026

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