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

Abandoned → [symfony/string](/?search=symfony%2Fstring)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

zenstruck/string
================

String utilities

v2.1.0(6y ago)332.2k1MITPHP

Since Sep 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/kbond/string)[ Packagist](https://packagist.org/packages/zenstruck/string)[ Docs](http://zenstruck.com/projects/string)[ RSS](/packages/zenstruck-string/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (6)Dependencies (1)Versions (8)Used By (1)

zenstruck/string
================

[](#zenstruckstring)

[![Build Status](https://camo.githubusercontent.com/9a1bf208315262e5d156a88b7c8da7d9748d1d9b4c94ca72036cf41339575290/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f6b626f6e642f737472696e672e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/kbond/string)[![Code Coverage](https://camo.githubusercontent.com/29cde371cc59becdeaf27638a17eb4971663f28537294d0520633d4340972fc1/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6b626f6e642f737472696e672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/kbond/string/)[![StyleCI](https://camo.githubusercontent.com/95bf753822d5af08f3652a6201d8ecf47079493f9ec41abec493e569e9d2711d/68747470733a2f2f7374796c6563692e696f2f7265706f732f32343130383830392f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/24108809)[![Latest Stable Version](https://camo.githubusercontent.com/4347758f0bad9df348de45aaa618c9b5f8462f1fa8cda7f5921293e2051f01f3/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a656e73747275636b2f737472696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zenstruck/string)[![License](https://camo.githubusercontent.com/10215d98f10845153f3663294b31f4a9dc34342d1960e56742c2c8083ee15e32/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a656e73747275636b2f737472696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zenstruck/string)

Various string utility functions for PHP. A [Twig Extension](https://github.com/kbond/string-twig) is available.

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

[](#installation)

```
composer require zenstruck/string

```

Usage
-----

[](#usage)

### remove\_whitespace

[](#remove_whitespace)

Replaces `&nbsp;` with a single space and converts multiple sequential spaces into a single space.

```
$ret = remove_whitespace("  foo &nbsp;   \n\n\n  \r  bar"); // $ret = "foo bar"
```

### null\_trim

[](#null_trim)

Similar to core "trim" but returns null instead of an empty string. When an array is passed, all elements get processed recursively.

```
$ret = null_trim(" foo  bar   "); // $ret = "foo bar"

$ret = null_trim("   "); // $ret = null

$ret = null_trim(array(" foo  bar   ", "   ")); // $ret = array("foo bar", null)

$ret = null_trim("foo / ", "/ "); // $ret = "foo"
```

### truncate\_word

[](#truncate_word)

Truncates text to a length without breaking words (calls `remove_whitespace` before truncating).

```
$ret = truncate_word("      foo       bar  baz", 10); // $ret = "foo bar..."
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

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

Every ~286 days

Recently: every ~297 days

Total

7

Last Release

2546d ago

Major Versions

v0.1.0 → v1.0.02016-02-24

v1.0.2 → v2.0.02016-10-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/707369cc916e0ea1aacbf077dcba464f611cef879f024d8944311a54a15224b3?d=identicon)[kbond](/maintainers/kbond)

---

Top Contributors

[![kbond](https://avatars.githubusercontent.com/u/127811?v=4)](https://github.com/kbond "kbond (11 commits)")

---

Tags

string

### Embed Badge

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

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

###  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.1k394.3M1.5k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[spatie/string

String handling evolved

5604.6M24](/packages/spatie-string)[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[kwn/number-to-words

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

4235.0M21](/packages/kwn-number-to-words)[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)

PHPackages © 2026

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