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

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

lukaswhite/string-utilities
===========================

Some miscellaneous string utilities for PHP

1.0.0(4y ago)092MITPHPCI failing

Since Sep 27Pushed 4y ago1 watchersCompare

[ Source](https://github.com/lukaswhite/string-utilities)[ Packagist](https://packagist.org/packages/lukaswhite/string-utilities)[ RSS](/packages/lukaswhite-string-utilities/feed)WikiDiscussions master Synced 2w ago

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

String Utilities
================

[](#string-utilities)

A few miscellanous PHP string utilities.

Strip Punctuation
-----------------

[](#strip-punctuation)

As the name suggests, the `stripPunctuation()` method strips all punctuation from a string.

```
Strings::stripPunctuation(
	'This, is a sentence, with - some - punctuation.'
);
// outputs This is a sentence with  some  punctuation
```

> To avoid the addtional spaces where the dashes have been replaced, see `stripMultipleSpaces()`

Strip Multiple Spaces
---------------------

[](#strip-multiple-spaces)

The `stripMultipleSpaces()` strips multiple spaces:

```
Strings::stripMultipleSpaces(
	'This is  a string that has  some extra spaces'
);
// outputs This is a string that has some extra spaces
```

Replace the nth Occurence of a Substring
----------------------------------------

[](#replace-the-nth-occurence-of-a-substring)

If you have a string that contains multiple occurences of a given substring, but only want to replace a specific one, use `replaceNth()`.

```
Strings::replaceNth( '0', '1', '0000000000', 5 );
// Outputs 0000100000
```

Replace All But First Occurence of a Substring
----------------------------------------------

[](#replace-all-but-first-occurence-of-a-substring)

If you have a string that contains multiple occurences of a given substring, but want to replace all but the first one then use `replaceAllButFirstOccurence()`.

```
Strings::replaceAllButFirstOccurence( '0', '1', '0000000000' );
// Outputs 0111111111
```

Random Hex String
-----------------

[](#random-hex-string)

The `randomHex()` method returns a random hexadecimal number, as a string, to the specified length.

```
Strings::randomHex( 5 );
// Outputs something like de0f42
```

To force it to be uppercase, pass `true` as the second argument.

```
Strings::randomHex( 5, true );
// Outputs something like DE0F42
```

Starts With
-----------

[](#starts-with)

Use `startsWith()` to determine whether a string starts with a specified substring.

```
Strings::startsWith( 'This is a test', 'This' )
// true
```

By default, the method is case sensitive. To make it case-insensitive, pass `false` as a third argument.

```
Strings::startsWith( 'This is a test', 'this', false )
// true
```

Ends With
---------

[](#ends-with)

Use `endsWith()` to determine whether a string ends with a specified substring.

```
Strings::startsWith( 'This is a test', 'test' )
// true
```

By default, the method is case sensitive. To make it case-insensitive, pass `false` as a third argument.

```
Strings::startsWith( 'This is a test', 'Test', false )
// true
```

Generate an Excerpt
-------------------

[](#generate-an-excerpt)

To generate an exceprt; as in, trim a string to a specified maximum number of words:

```
$excerpt = Strings::excerpt( $content, 25 );
```

By default this appends `...` to the end of the string; change this using the optional third argument, for example:

```
$excerpt = Strings::excerpt(
	$content,
	100,
	'Read More'
);
```

Alternatively, if you need to limit the length of the excerpt to a specified number of characters:

```
$excerpt = Strings::excerptCharacters( $content, 200 );
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

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 ~217 days

Recently: every ~267 days

Total

6

Last Release

1750d ago

Major Versions

0.0.5 → 1.0.02021-09-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1bd633ffdf0f66a73a288c4edcacfa43d214cd95a53384c6fe5ea4b3554dd9d?d=identicon)[lukaswhite](/maintainers/lukaswhite)

---

Top Contributors

[![lukaswhite](https://avatars.githubusercontent.com/u/999014?v=4)](https://github.com/lukaswhite "lukaswhite (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[hirethunk/verbs

An event sourcing package that feels nice.

515217.0k7](/packages/hirethunk-verbs)[topthink/think-helper

The ThinkPHP6 Helper Package

812.5M251](/packages/topthink-think-helper)[hmaus/drafter-php

PHP wrapper around drafter binary

32128.5k5](/packages/hmaus-drafter-php)[pear/fsm

Finite State Machine

355.0k](/packages/pear-fsm)[justkidding96/aardvark-seo

Save time and get your Statamic site to rank better with the SEO addon for Statamic.

155.4k](/packages/justkidding96-aardvark-seo)

PHPackages © 2026

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