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

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

dvlpr1996/php-string-helpers
============================

Some Useful Php String Helper Methods

v3.0.0(2y ago)00MITPHPPHP ^8.1

Since Nov 23Pushed 2y ago1 watchersCompare

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

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

Helpful Set Of Php String Helper Functions Utilities Class
==========================================================

[](#helpful-set-of-php-string-helper-functions-utilities-class)

[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)[![Latest Version on Packagist](https://camo.githubusercontent.com/e85fcf3f982c0aef17fa6b5653ae48ca018c1d96baeb8ed56cae7dfd2d63e5b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64766c7072313939362f7068702d737472696e672d68656c706572733f7374796c653d666c6174)](https://packagist.org/packages/dvlpr1996/php-string-helpers)[![Total Downloads](https://camo.githubusercontent.com/fa302f00a963df7dccb22301050ac4289e0883238de6b3d8e0f7cf4b51a10c9a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64766c7072313939362f7068702d737472696e672d68656c70657273)](https://packagist.org/packages/dvlpr1996/php-string-helpers)

All function helpers will be enabled by default (if those functions haven't already been defined). also you can use them as utilities class.

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

[](#requirements)

- PHP 8.1 or higher

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

[](#installation)

You can install the package via composer:

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

StrUtility usage as static methods
----------------------------------

[](#strutility-usage-as-static-methods)

you can use String helper methods as static so usage like the following: First Using The StrUtility Class:

```
use dvlpr1996\PhpStringHelpers\Facade\StrUtility;
```

- change words to camel case

```
StrUtility::toCamelCase(string $words): string
```

- change words to pascal case

```
StrUtility::toPascalCase(string $words): string
```

- change words to kebab case

```
StrUtility::toKebabCase(string $words): string
```

- change words to title case

```
StrUtility::toTitleCase(string $words): string
```

- change words to constant case | foo bar baz change to FOO\_BAR\_BAZ

```
StrUtility::toConstant(string $words): string
```

- change words to snake case

```
StrUtility::toSnakeCase(string $words): string
```

- change words to path case | foo bar baz change to foo/bar/baz

```
StrUtility::toPathCase(string $words): string
```

- change words to ada case | foo bar change to Foo\_Bar

```
StrUtility::toAdaCase(string $words): string
```

- change words to dot notation case | foo bar change to foo.bar

```
StrUtility::dotNotation(string $words): string
```

- wrapper for htmlspecialchars()

```
StrUtility::entitiesWrapper($data): string
```

- change string to slug

```
StrUtility::toSlug(string $string): string
```

- remove all blanks

```
StrUtility::rmAllBlanks(string $string): string
```

- return alternate string if string param is null

```
StrUtility::alternate(?string $string, string $alternate = null): string
```

- translation methods, for using this method you should create a wrapper function for example

```
function (string $key, string $alternative = '', string $dirName = 'en')
{
    $BASE_PATH = // base (root) path of your project

    $translatePath = StrUtility::translatePath($BASE_PATH, $dirName);
    return StrUtility::translate($translatePath . $key, $alternative);
}
```

&lt; your\_wrapper\_function\_name&gt;('app.title') reference to lang/en/app.php and title array key in app.php file app.php must only return associative array. this translation methods only work for one level

```
StrUtility::translate(string $key, string $alternative = ''): string|array
```

- wrap given string with wrapper param

```
StrUtility::wrapper(int|string $string, int|string $wrapper = '*'): string
```

- return path of file

```
StrUtility::filePath(string $path, string $pathExtension = 'php'): string
```

- generate unique pin numbers between 4 digit and 12 digit

```
StrUtility::generatePin(int $length = 4): int
```

- clean and safe given string data

```
StrUtility::clearString(string $data): string
```

- return only string and remove other characters

```
StrUtility::pureString(string $data): string
```

- generate random string

```
StrUtility::randomChar(int $size = 5): string
```

- generate random hexadecimal color

```
StrUtility::randomHex(): string
```

- generate random rgb color

```
StrUtility::randomRgb(): string
```

- Remove all types of links

```
StrUtility::rmLink(string $string): string
```

- limit character based on $length and replace theme with ...

```
StrUtility::limitChar(string|int $string, int $length): string
```

- generate unique id numbers

```
StrUtility::generateId(string|int $prefix ='',string|int $suffix ='',bool $moreEntropy = false): string
```

- remove all numbers

```
StrUtility::rmNumbers(string $string): string
```

- remove all characters

```
StrUtility::rmCharacters(string $string): string
```

- remove all extra blanks

```
StrUtility::rmExtraBlank(string $string): string
```

- convert hex color to rgb color

```
StrUtility::hexToRgb(string $color): ?string
```

- convert rgb color to hex color

```
StrUtility::rgbToHex(string $color): ?string
```

- generate &lt;a&gt; tag link

```
StrUtility::generateAnchor(string|int $content, string $href): string
```

- return encoding of string . wrapper for mb\_detect\_encoding()

```
StrUtility::getEncoding(string $string): string
```

```
StrUtility::isUtf8(string|array $string): bool
```

- remove duplicate words

```
StrUtility::rmDuplicateWords(string $string): string
```

- remove characters from right side based on $num param

```
StrUtility::rmRightChar(string $words, int $num): string
```

- remove characters from left side based on $num param

```
StrUtility::rmLeftChar(string $words, int $num): string
```

- remove characters from both side based on $num param

```
StrUtility::rmBothSideChar(string $words, int $num): string
```

- find whether the type of a data is json

```
StrUtility::isJson(mixed $data): bool
```

- Checks whether the string contains the specified value or not

```
StrUtility::isContains(string $string, string $search, bool $caseSensitive = false): bool
```

- Checks whether the string starts with the specified value &lt;$search&gt; or not

```
StrUtility::isStartWith(string $string, string $search, bool $caseSensitive = false): bool
```

- return the last word

```
StrUtility::lastWord(string $string): string
```

- return the first word

```
StrUtility::firstWord(string $string): string
```

- return the first number

```
StrUtility::getFirstNumbers(string $string): string
```

- return the last number

```
StrUtility::getLastNumbers(string $string): string
```

```
StrUtility::rmBeginningNumbers(string $string): string
```

```
StrUtility::rmEndingNumbers(string $string): string
```

```
StrUtility::convertToUtf8(string $string): string|bool
```

- incrementing the numbers of the end of the string

```
StrUtility::incrementBy(string $string, ?string $separator = null): string
```

- decrementing the numbers of the end of the string

```
StrUtility::decrementBy(string $string, ?string $separator = null): string
```

- remove last word from given string

```
StrUtility::rmLastWord(string $string): string
```

- remove first word from given string

```
StrUtility::rmFirstWord(string $string): string
```

- find whether the type of a given string is slug

```
StrUtility::is_slug(string $slug): bool
```

- find whether the type of a given ip is valid ipv4

```
StrUtility::is_ipv4(string $ip): bool
```

- find whether the type of a given ip is valid ipv6

```
StrUtility::is_ipv6(string $ip): bool
```

- Deletes the words before the given $search word

```
StrUtility::after(string $string, string $search): string
```

- Deletes the words after the given $search word

```
StrUtility::before(string $string, string $search): string
```

```
StrUtility::hasSpace(string $string): bool
```

```
StrUtility::isEmail(string $email): bool
```

```
StrUtility::detectCase(string $word): string
```

```
StrUtility::isLowerCase(string $word): bool
```

```
StrUtility::isUpperCase(string $word): bool
```

```
StrUtility::isTitleCase(string $word): bool
```

```
StrUtility::isSnakeCase(string $word): bool
```

```
StrUtility::validateUserName(string $userName, int $min = 3, int $max = 20): bool
```

```
StrUtility::humanFileSize(int $size, string $type = 'KB'): string
```

StrUtility usage as helper functions
------------------------------------

[](#strutility-usage-as-helper-functions)

String helper functions are global so usage like the following:

```
decrementBy(string $string, ?string $separator = null): string
```

StrUtility usage as object
--------------------------

[](#strutility-usage-as-object)

```
use PhpStringHelpers\utility\StrUtility;

$string = new StrUtility;

$string->toConstant('foo bar baz');
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

issues
------

[](#issues)

If you discover any issues, please using the issue tracker.

Credits
-------

[](#credits)

- [Nima jahan bakhshian](https://github.com/dvlpr1996)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Recently: every ~129 days

Total

6

Last Release

743d ago

Major Versions

v0.1.1 → v1.0.02022-12-18

v1.0.0 → v2.0.02023-01-18

v2.0.1 → v3.0.02024-05-06

PHP version history (2 changes)v0.1.0PHP ^8.0

v3.0.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![dvlpr1996](https://avatars.githubusercontent.com/u/93678876?v=4)](https://github.com/dvlpr1996 "dvlpr1996 (37 commits)")

---

Tags

phpphp-helperphp-libraryphp-stringphp-string-helperphp8stringstring-helperstring-utilitiesphpstringhelpershelper-methodsphp-string-helpersphp-string-helpers-method

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[transprime-research/piper

PHP Pipe method execution with values from chained method executions

174.6k2](/packages/transprime-research-piper)

PHPackages © 2026

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