PHPackages                             fab2s/strings - 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. fab2s/strings

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

fab2s/strings
=============

A purely static String Helper to handle more advanced utf8 string manipulations

1.0.2(4y ago)2309.1k↓25%[1 PRs](https://github.com/fab2s/Strings/pulls)2MITPHPPHP ^7.1|^8.0CI failing

Since Sep 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/fab2s/Strings)[ Packagist](https://packagist.org/packages/fab2s/strings)[ RSS](/packages/fab2s-strings/feed)WikiDiscussions master Synced 1mo ago

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

Strings
=======

[](#strings)

[![Build Status](https://camo.githubusercontent.com/45772a0a641198573fa7d3520d7e895a58ef9ae5e989a3446071686e656e6ce4/68747470733a2f2f7472617669732d63692e636f6d2f66616232732f537472696e67732e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/fab2s/Strings) [![Total Downloads](https://camo.githubusercontent.com/e0be5e99b73407e4acd6c34232a7a7c1c2b5284d52a8eea0f4312547cab77a3b/68747470733a2f2f706f7365722e707567782e6f72672f66616232732f737472696e67732f646f776e6c6f616473)](//packagist.org/packages/fab2s/strings) [![Monthly Downloads](https://camo.githubusercontent.com/57d20719addd8b7f5a4febf28b6dff28a721309774af5aff22238250721a74a0/68747470733a2f2f706f7365722e707567782e6f72672f66616232732f737472696e67732f642f6d6f6e74686c79)](//packagist.org/packages/fab2s/strings) [![Latest Stable Version](https://camo.githubusercontent.com/7c00b7416e297d6a4f678d3e6dfb76a4335b2ce9146ab68e234376f1b7b0a5b9/68747470733a2f2f706f7365722e707567782e6f72672f66616232732f737472696e67732f762f737461626c65)](https://packagist.org/packages/fab2s/strings) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/df6058adfe49fca167129a42d9fd0c5c91dc154c2d2861accdcbdc131899af9d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f66616232732f737472696e67732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/fab2s/Strings/?branch=master) [![PRs Welcome](https://camo.githubusercontent.com/7d9ed3c8f22eceb1711573169b1390cc0b1194467340dc815205060c162b5309/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c6174)](http://makeapullrequest.com) [![License](https://camo.githubusercontent.com/91d1212ccc7960f203a90fe7b556a30f78d37beb96f55433a176ee31e1afff41/68747470733a2f2f706f7365722e707567782e6f72672f66616232732f737472696e67732f6c6963656e7365)](https://packagist.org/packages/fab2s/strings)

A purely static String Helper to handle more advanced utf8 string manipulations

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

[](#installation)

`Strings` can be installed using composer:

```
composer require "fab2s/strings"

```

`Strings` is also included in [OpinHelper](https://github.com/fab2s/OpinHelpers) which packages several bellow "Swiss Army Knife" level Helpers covering some of the most annoying aspects of php programing, such as UTF8 string manipulation, high precision Mathematics or properly locking a file

Should you need to work with php bellow 7.1, you can still use [OpinHelper](https://github.com/fab2s/OpinHelpers) `0.x`

Prerequisites
-------------

[](#prerequisites)

As it requires `Utf8`, `Strings` requires [mb\_string](https://php.net/mb_string), [ext-intl](https://php.net/intl) is auto detected and used when available for UTF-8 Normalization

In practice
-----------

[](#in-practice)

`Strings` implement some basic text manipulation function that can be pretty useful IRL

- `filter(string $string):string`

    Drops Zero Width white chars, normalizes EOL and Normalize UTF8 if [ext-intl](https://php.net/intl) is available
- `singleWsIze(string $string, bool $normalize = false, bool $includeTabs = true):string`

    Replace repeated white-spaces to a single one, preserve original white-spaces unless normalized (every white-spaces to ' '), with or without tabs (\\t)
- `singleLineIze(string $string):string`

    Make string fit in one line by replacing EOLs and white-spaces to normalized single white-spaces
- `dropZwWs(string $string):string`

    Remove Zero Width white-spaces
- `normalizeWs(string $string, bool $includeTabs = true, int $maxConsecutive = null):string`

    Normalize white-spaces to a single ` ` by default, include tabs by default
- `normalizeEol($string, $maxConsecutive = null, $eol = self::EOL):string`

    Normalize EOLs to a single LF by default
- `normalizeText(string $text):string`

    Return `trim`'d and `filter`'d $text
- `normalizeTitle(string $title):string`

    Return `singleLineIze`'d, `normalizeWs`'d, `normalizeText`'d and `ucfirst`'d $title (`" the best ever \t\r\n article"` -&gt; `"The best ever article"`)
- `normalizeName(string $name):string`

    Return `ucword`'d and `normalizeTitle`'d $name (`"john \n\t doe  "` -&gt; `"John Doe"`)
- `escape(string $string, int $flag = ENT_COMPAT, bool $hardEscape = true):string`

    [htmlspecialchars()](https://php.net/htmlspecialchars) wrapper with UTF8 set as encoding
- `softEscape(string $string, int $flag = ENT_COMPAT):string`

    Shortcut for `escape(string $string, $flag, true)`
- `unEscape(string $string, int $quoteStyle = ENT_COMPAT):string`

    [htmlspecialchars\_decode()](https://php.net/htmlspecialchars_decode) wrapper
- `convert(string $string, string $from = null, string $to = self::ENCODING):string`

    Convert encoding to UTF8 by default. Basic $from encoding detection using `Strings::detectEncoding()`
- `detectEncoding(string $string):string|null`

    Detect encoding by checking `Utf8::isUf8()`, then trying with BOMs and ultimately fall back to [mb\_detect\_encoding()](https://php.net/mb_detect_encoding) with limited charsets first, then more internally in [mb\_convert\_encoding()](https://php.net/mb_convert_encoding)
- `secureCompare(string $test, string $reference):bool`

    Perform a [Timing Attack](https://en.wikipedia.org/wiki/Timing_attack) safe string comparison (Truly constant operations comparison)
- `contentHash(string $content):string`

    Return a `sha256` hash of the $content prefixed with $content length. Indented to quickly and reliably detect $content updates.

Requirements
------------

[](#requirements)

`Strings` is tested against php 7.2, 7.3, 7.4 and 8.0

Contributing
------------

[](#contributing)

Contributions are welcome, do not hesitate to open issues and submit pull requests.

License
-------

[](#license)

`Strings` is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity66

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

Every ~317 days

Total

3

Last Release

1797d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.1

1.0.2PHP ^7.1|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7323989?v=4)[fab2s](/maintainers/fab2s)[@fab2s](https://github.com/fab2s)

---

Top Contributors

[![fab2s](https://avatars.githubusercontent.com/u/7323989?v=4)](https://github.com/fab2s "fab2s (10 commits)")

---

Tags

helperphpsimplestringstring-manipulationutf-8phpnormalizehelperutf-8utf8stringsSimpleeolwhite-spaceend-of-lineconstant-time-compare

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fab2s-strings/health.svg)

```
[![Health](https://phpackages.com/badges/fab2s-strings/health.svg)](https://phpackages.com/packages/fab2s-strings)
```

###  Alternatives

[voku/portable-utf8

Portable UTF-8 library - performance optimized (unicode) string functions for php.

52322.4M40](/packages/voku-portable-utf8)[zjkal/time-helper

一个简单快捷的PHP日期时间助手类库。 a smart PHP datetime helper library.

21128.6k1](/packages/zjkal-time-helper)[fab2s/souuid

Simple Ordered Uuid Generator in PHP

13573.2k1](/packages/fab2s-souuid)

PHPackages © 2026

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