junaidkhan/php-string-helper
Composer 安装命令:
composer require junaidkhan/php-string-helper
包简介
A PHP helper library offering utilities like truncate, slugify, casing conversions, and more.
关键字:
README 文档
README
String Helper is a PHP helper library for common string operations, built for PHP 8+.
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, andkebab-case
Installation
Install via Composer:
composer require junaidkhan/php-string-helper
Usage
1. Autoload with Composer
require 'vendor/autoload.php';
2. Import the class
use JunaidKhan\StringHelper\StringHelper;
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
| Method | Parameters | Description |
|---|---|---|
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
This project is licensed under the MIT License. See the LICENSE file for details.
🙌 Contributing
Contributions are welcome! Feel free to fork the repository, open issues, or submit pull requests to help improve the package.
junaidkhan/php-string-helper 适用场景与选型建议
junaidkhan/php-string-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 7, 最近一次更新时间为 2025 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「json」 「helpers」 「library」 「truncate」 「formatter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 junaidkhan/php-string-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 junaidkhan/php-string-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 junaidkhan/php-string-helper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
HTML and form generation
Falsy helps you manage half-truths with PHP
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-19