dvlpr1996/php-string-helpers
Composer 安装命令:
composer require dvlpr1996/php-string-helpers
包简介
Some Useful Php String Helper Methods
README 文档
README
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
- PHP 8.1 or higher
Installation
You can install the package via composer:
composer require dvlpr1996/php-string-helpers
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 <your_wrapper_function_name>(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); }
< your_wrapper_function_name>('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 <a> 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 <$search> 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
String helper functions are global so usage like the following:
decrementBy(string $string, ?string $separator = null): string
StrUtility usage as object
use PhpStringHelpers\utility\StrUtility; $string = new StrUtility; $string->toConstant('foo bar baz');
Changelog
Please see CHANGELOG for more information what has changed recently.
issues
If you discover any issues, please using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
dvlpr1996/php-string-helpers 适用场景与选型建议
dvlpr1996/php-string-helpers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「helpers」 「string」 「helper-methods」 「php-string-helpers」 「php-string-helpers-method」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dvlpr1996/php-string-helpers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dvlpr1996/php-string-helpers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dvlpr1996/php-string-helpers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Encode integer IDs using a preset or customized symbol set
base62 encoder and decoder also for big numbers with Laravel integration
PHP string processing library.
Сумма прописью
HTML and form generation
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-28