PHPackages                             bayfrontmedia/php-string-helpers - 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. bayfrontmedia/php-string-helpers

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

bayfrontmedia/php-string-helpers
================================

Helper class to provide useful string functions.

v2.3.1(4mo ago)03.7k—0%16MITPHPPHP ^8.0

Since Jul 27Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/bayfrontmedia/php-string-helpers)[ Packagist](https://packagist.org/packages/bayfrontmedia/php-string-helpers)[ Docs](https://github.com/bayfrontmedia/php-string-helpers)[ RSS](/packages/bayfrontmedia-php-string-helpers/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)DependenciesVersions (10)Used By (6)

PHP string helpers
------------------

[](#php-string-helpers)

PHP helper class to provide useful string functions.

- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Author
------

[](#author)

[![Bayfront Media](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)

- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)

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

[](#requirements)

- PHP `^8.0` (Tested up to `8.4`)

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

[](#installation)

```
composer require bayfrontmedia/php-string-helpers

```

Usage
-----

[](#usage)

- [startWith](#startwith)
- [endWith](#endwith)
- [lowercase](#lowercase)
- [uppercase](#uppercase)
- [titleCase](#titlecase)
- [camelCase](#camelcase)
- [kebabCase](#kebabcase)
- [snakeCase](#snakecase)
- [random](#random)
- [uid](#uid)
- [uuid4](#uuid4)
- [uuid7](#uuid7)
- [isValidUuid](#isvaliduuid)
- [binToUuid](#bintouuid)
- [uuidToBin](#uuidtobin)
- [hasComplexity](#hascomplexity)

Depreciated:

- [has](#has)
- [hasSpace](#hasspace)
- [startsWith](#startswith)
- [endsWith](#endswith)
- [uuid](#uuid)

---

### startWith

[](#startwith)

**Description:**

Returns string, ensuring that it starts with a given string.

**Parameters:**

- `$string` (string)
- `$start_with` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

echo Str::startWith($string, 'Hello! ');
```

---

### endWith

[](#endwith)

**Description:**

Returns string, ensuring that it ends with a given string.

**Parameters:**

- `$string` (string)
- `$end_with` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

echo Str::endWith($string, ' Goodbye!');
```

---

### lowercase

[](#lowercase)

**Description:**

Converts string to lowercase using a specified character encoding.

See:

**Parameters:**

- `$string` (string)
- `$encoding = 'UTF-8'` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

echo Str::lowercase($string);
```

---

### uppercase

[](#uppercase)

**Description:**

Converts string to uppercase using a specified character encoding.

See:

**Parameters:**

- `$string` (string)
- `$encoding = 'UTF-8'` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

echo Str::uppercase($string);
```

---

### titleCase

[](#titlecase)

**Description:**

Converts string to title case using a specified character encoding.

See:

**Parameters:**

- `$string` (string)
- `$encoding = 'UTF-8'` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

echo Str::titleCase($string);
```

---

### camelCase

[](#camelcase)

**Description:**

Converts string to camel case, removing any non-alpha and non-numeric characters.

**Parameters:**

- `$string` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

echo Str::camelCase($string);
```

---

### kebabCase

[](#kebabcase)

**Description:**

Converts string to kebab case (URL-friendly slug), replacing any non-alpha and non-numeric characters with a hyphen.

**Parameters:**

- `$string` (string)
- `$lowercase = false` (bool): Convert string to lowercase

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

echo Str::kebabCase($string);
```

---

### snakeCase

[](#snakecase)

**Description:**

Converts string to snake case, replacing any non-alpha and non-numeric characters with an underscore.

**Parameters:**

- `$string` (string)
- `$lowercase = false` (bool): Convert string to lowercase

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

echo Str::snakeCase($string);
```

---

### random

[](#random)

**Description:**

Return a random string of specified length and type.

**Note: Returned string is not cryptographically secure.**

**Parameters:**

- `$length = 8` (int)
- `$type = self::RANDOM_TYPE_ALL` (string): Any `RANDOM_TYPE_*` constant)

Valid `$type` constants include:

- `RANDOM_TYPE_NONZERO`
- `RANDOM_TYPE_NUMERIC`
- `RANDOM_TYPE_ALPHA`: Alphabetic, upper and lowercase
- `RANDOM_TYPE_ALPHA_LOWER`
- `RANDOM_TYPE_ALPHA_UPPER`
- `RANDOM_TYPE_ALPHANUMERIC`: Alphanumeric, upper and lowercase
- `RANDOM_TYPE_ALPHANUMERIC_LOWER`
- `RANDOM_TYPE_ALPHANUMERIC_UPPER`
- `RANDOM_TYPE_ALL`: Alphanumeric and special characters

Backticks and quotation marks are excluded from special characters for safely inserting into a database.

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

echo Str::random(16, Str::RANDOM_TYPE_ALPHANUMERIC);
```

---

### uid

[](#uid)

**Description:**

Return a cryptographically secure unique identifier (UID) comprised of lowercase letters and numbers.

**Parameters:**

- `$length = 8` (int)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

echo Str::uid(16);
```

### uuid4

[](#uuid4)

**Description:**

Return a UUID v4 string.

**Parameters:**

- (None)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

echo Str::uuid4();
```

---

### uuid7

[](#uuid7)

**Description:**

Return a lexicographically sortable UUID v7 string.

**Parameters:**

- (None)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

echo Str::uuid7();
```

---

### isValidUuid

[](#isvaliduuid)

**Description:**

Is string a valid UUID?

**Parameters:**

- `$uuid` (string)

**Returns:**

- (boolean)

**Example:**

```
use Bayfront\StringHelpers\Str;

if (!Str::isValidUuid('9b77a49f-5d5a-4699-a8e0-21d010fdd9bc')) {
    // Do something
}
```

---

### binToUuid

[](#bintouuid)

**Description:**

Convert 16 byte binary string to UUID.

**Parameters:**

- `$binary` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$uuid = Str::binToUuid($binary);
```

---

### uuidToBin

[](#uuidtobin)

**Description:**

Convert UUID to 16 byte binary string.

**Parameters:**

- `$uuid` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

$bin = Str::uuidToBin('9b77a49f-5d5a-4699-a8e0-21d010fdd9bc');
```

---

### hasComplexity

[](#hascomplexity)

**Description:**

Verify input string has a specified complexity.

**Parameters:**

- `$string` (string)
- `$min_length` (int)
- `$max_length` (int): `0` for no max
- `$lowercase` (int): Minimum number of lowercase characters
- `$uppercase` (int): Minimum number of uppercase characters
- `$digits` (int): Minimum number of digits
- `$special_chars` (int): Minimum number of non-alphabetic and non-numeric characters

**Returns:**

- (bool)

**Example:**

```
use Bayfront\StringHelpers\Str;

if (!Str::hasComplexity('abc123', 8, 32, 1, 1, 1, 1)) {
    // Do something
}
```

---

### has

[](#has)

**Description:**

Checks if string contains a case-sensitive needle.

This method has been depreciated in favor of PHP native function `str_contains`.

**Parameters:**

- `$string` (string)
- `$needle` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

if (Str::has($string, 'this')) {

    // Do something

}
```

---

### hasSpace

[](#hasspace)

**Description:**

Checks if string contains any whitespace.

This method has been depreciated in favor of PHP native function `str_contains`.

**Parameters:**

- `$string` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

if (Str::hasSpace($string)) {

    // Do something

}
```

---

### startsWith

[](#startswith)

**Description:**

Checks if a string starts with a given case-sensitive string.

This method has been depreciated in favor of PHP native function `str_starts_with`.

**Parameters:**

- `$string` (string)
- `$starts_with` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

if (Str::startsWith($string, 'this')) {

    // Do something

}
```

---

### endsWith

[](#endswith)

**Description:**

Checks if a string ends with a given case-sensitive string.

This method has been depreciated in favor of PHP native function `str_ends_with`.

**Parameters:**

- `$string` (string)
- `$ends_with` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\StringHelpers\Str;

$string = 'This is a string.';

if (Str::endsWith($string, 'string.')) {

    // Do something

}
```

---

### uuid

[](#uuid)

**Description:**

Return a UUID v4 string.

This method has been depreciated in favor of [Str::uuid4](#uuid4) and [Str::uuid7](#uuid7).

**Parameters:**

- (None)

**Returns:**

- (string)

**Example:**

```
use Bayfront\StringHelpers\Str;

echo Str::uuid();
```

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance77

Regular maintenance activity

Popularity21

Limited adoption so far

Community15

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

Recently: every ~117 days

Total

9

Last Release

124d ago

Major Versions

v1.2.0 → v2.0.02023-01-26

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

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad62c8d0e69358fd63b16fdaa71d5359231cd0cf660bbc3419071dc705c63a8?d=identicon)[bayfrontmedia](/maintainers/bayfrontmedia)

---

Top Contributors

[![robinsonjohn](https://avatars.githubusercontent.com/u/24327848?v=4)](https://github.com/robinsonjohn "robinsonjohn (14 commits)")

---

Tags

functionhelperhelpersphpstringphphelperstringhelpersfunction

### Embed Badge

![Health badge](/badges/bayfrontmedia-php-string-helpers/health.svg)

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

###  Alternatives

[laravelista/ekko

Framework agnostic PHP package for marking navigation items active.

278673.4k4](/packages/laravelista-ekko)[clausnz/php-helpers

A Collection of useful php helper functions.

388.7k](/packages/clausnz-php-helpers)[bayfrontmedia/php-array-helpers

Helper class to provide useful array functions.

1413.4k23](/packages/bayfrontmedia-php-array-helpers)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)

PHPackages © 2026

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