PHPackages                             junaidkhan/php-string-helper - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. junaidkhan/php-string-helper

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

junaidkhan/php-string-helper
============================

A PHP helper library offering utilities like truncate, slugify, casing conversions, and more.

v0.1.0(1y ago)725MITPHPPHP &gt;=8.0CI passing

Since Apr 19Pushed 1y ago1 watchersCompare

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

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

String Helper
=============

[](#string-helper)

[![Packagist](https://camo.githubusercontent.com/b1399b1d89e1366c08f46c00ab835f5336320774f9fd196a07b5d01022c137f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a756e6169646b68616e2f7068702d737472696e672d68656c706572)](https://packagist.org/packages/junaidkhan/php-string-helper)[![PHP Version](https://camo.githubusercontent.com/f23a3290357e224d21c643c2286f1dac1340170aea90656fc649bb8d8d99db58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a756e6169646b68616e2f7068702d737472696e672d68656c706572)](https://packagist.org/packages/junaidkhan/php-string-helper)[![Downloads](https://camo.githubusercontent.com/fd595880e94f67af0a6ff56d5224aa439e357c3c1f007d3c105c344bf68506ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756e6169646b68616e2f7068702d737472696e672d68656c706572)](https://packagist.org/packages/junaidkhan/php-string-helper)[![License](https://camo.githubusercontent.com/b8799726b9f6d191ae8518443ce55ae659277df11ba92a06969c0fc35f12aad0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a756e6169646b68616e3434342f7068702d737472696e672d68656c706572)](https://github.com/junaidkhan444/php-string-helper/blob/main/LICENSE)[![Issues](https://camo.githubusercontent.com/99d9d3749c56a0a19c129e4c6ea42370ec8c234ce428298f9c9989270de1d5ce/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6a756e6169646b68616e3434342f7068702d737472696e672d68656c706572)](https://github.com/junaidkhan444/php-string-helper/issues)[![Contributors](https://camo.githubusercontent.com/7959f5b165a2a1cdb6a68a25b74a02fc8974d7e6e39e099e8467efe4c7101519/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6a756e6169646b68616e3434342f7068702d737472696e672d68656c706572)](https://github.com/junaidkhan444/php-string-helper/graphs/contributors)[![Tests](https://github.com/junaidkhan444/php-string-helper/actions/workflows/tests.yml/badge.svg)](https://github.com/junaidkhan444/php-string-helper/actions/workflows/tests.yml)

**String Helper** is a PHP helper library for common string operations, built for PHP 8+.

---

Features
--------

[](#features)

- Truncate strings by character count (with word-safe, custom suffixes and HTML-stripping or HTML-preserving)
- Limit strings by word count with custom suffixes
- Check if strings start with, end with, or contain a substring
- Remove special characters with optional Unicode, dash, or underscore preservation
- Reverse strings easily
- Detect valid JSON strings with a simple check
- Create clean slugs for URLs or SEO
- Convert strings to `camelCase`, `snake_case`, and `kebab-case`

---

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

[](#installation)

Install via Composer:

```
composer require junaidkhan/php-string-helper
```

Usage
-----

[](#usage)

### 1. Autoload with Composer

[](#1-autoload-with-composer)

```
require 'vendor/autoload.php';
```

### 2. Import the class

[](#2-import-the-class)

```
use JunaidKhan\StringHelper\StringHelper;
```

### 3. Use the methods

[](#3-use-the-methods)

```
// Slugify
echo StringHelper::slugify('  Mastering PHP in 2025!  '); // master-php-in-2025

// Case conversions
echo StringHelper::toCamelCase('modern_php_tutorial');       // modernPhpTutorial
echo StringHelper::toSnakeCase('modernPhpTutorial');         // modern_php_tutorial
echo StringHelper::toKebabCase('modernPhpTutorial');         // modern-php-tutorial

// String checks
echo StringHelper::startsWith('FrameworkX', 'Frame');         // true
echo StringHelper::endsWith('SuperTool', 'Tool');             // true
echo StringHelper::contains('Debugging helps developers', 'help'); // true

// Truncate with suffix (text, maxLength, suffix, wordSafe, stripHtml, preserveHtml)
echo StringHelper::truncate('Mastering PHP in 2025!', 15, '...', true, false, false); // Mastering PHP...

// Limit words with suffix (text, wordLimit, suffix)
echo StringHelper::limitWords('Master PHP with real-world projects', 3, '...'); // Master PHP with...

// Reverse string (text)
echo StringHelper::reverse('Productivity'); // ytivitcudorP

// Remove special characters (text, preserveUnderscore, preserveDash, allowUnicode)
echo StringHelper::removeSpecialChars('E-mail@example.com!', false, false, false); // Emailexamplecom

// Check valid JSON (string)
echo StringHelper::isJson('{"valid":true}'); // true
```

---

Methods
-------

[](#methods)

MethodParametersDescription`slugify``string $string`Convert a string into a URL-friendly slug`toCamelCase``string $text`Convert to camelCase`toSnakeCase``string $text`Convert to snake\_case`toKebabCase``string $text`Convert to kebab-case`startsWith``string $haystack, string $needle`Check if string starts with a given substring`endsWith``string $haystack, string $needle`Check if string ends with a given substring`contains``string $haystack, string $needle`Check if string contains a given substring`truncate``string $text, int $maxLength, string $suffix, bool $wordSafe, bool $stripHtml, bool $preserveHtml`Truncate string with full support for HTML, suffix, and word-safety`limitWords``string $text, int $wordLimit, string $suffix`Limit string by number of words, appending suffix if trimmed`reverse``string $text`Reverse the given string`removeSpecialChars``string $text, bool $preserveUnderscore, bool $preserveDash, bool $allowUnicode`Remove all non-alphanumeric characters (with optional preservation)`isJson``string $string`Check if the string is valid JSON---

📄 License
---------

[](#-license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

---

🙌 Contributing
--------------

[](#-contributing)

Contributions are welcome! Feel free to fork the repository, open issues, or submit pull requests to help improve the package.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance48

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

394d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a2c9848ad24e226f305849fb5d4c21caba3cffea77ad9f7ac703c14fc7e2d4cb?d=identicon)[junaid-khan](/maintainers/junaid-khan)

---

Top Contributors

[![JunaidKhan444](https://avatars.githubusercontent.com/u/42815406?v=4)](https://github.com/JunaidKhan444 "JunaidKhan444 (27 commits)")

---

Tags

composer-packagehelpers-libraryphpphpjsonformatterslugslugifystringhelperslibrarystring manipulationtext-processingkebab casesnake casecamelcasereversetruncatestring-helperstring utilitieslimit words

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/junaidkhan-php-string-helper/health.svg)

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

###  Alternatives

[dragon-code/codestyler

A tool to automatically fix Coding Style Standards issues by The Dragon Code.

291.8M16](/packages/dragon-code-codestyler)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[phppkg/config

Config manage, load, get. Supports INI,JSON,YAML,NEON,PHP format file

133.5k](/packages/phppkg-config)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[bupy7/xml-constructor

The array-like constructor of XML document structure.

1337.9k](/packages/bupy7-xml-constructor)

PHPackages © 2026

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