bayfrontmedia/php-string-helpers
Composer 安装命令:
composer require bayfrontmedia/php-string-helpers
包简介
Helper class to provide useful string functions.
README 文档
README
PHP helper class to provide useful string functions.
License
This project is open source and available under the MIT License.
Author
Requirements
- PHP
^8.0(Tested up to8.4)
Installation
composer require bayfrontmedia/php-string-helpers
Usage
- startWith
- endWith
- lowercase
- uppercase
- titleCase
- camelCase
- kebabCase
- snakeCase
- random
- uid
- uuid4
- uuid7
- isValidUuid
- binToUuid
- uuidToBin
- hasComplexity
Depreciated:
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
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
Description:
Converts string to lowercase using a specified character encoding.
See: https://www.php.net/manual/en/mbstring.supported-encodings.php
Parameters:
$string(string)$encoding = 'UTF-8'(string)
Returns:
- (string)
Example:
use Bayfront\StringHelpers\Str; $string = 'This is a string.'; echo Str::lowercase($string);
uppercase
Description:
Converts string to uppercase using a specified character encoding.
See: https://www.php.net/manual/en/mbstring.supported-encodings.php
Parameters:
$string(string)$encoding = 'UTF-8'(string)
Returns:
- (string)
Example:
use Bayfront\StringHelpers\Str; $string = 'This is a string.'; echo Str::uppercase($string);
titleCase
Description:
Converts string to title case using a specified character encoding.
See: https://www.php.net/manual/en/mbstring.supported-encodings.php
Parameters:
$string(string)$encoding = 'UTF-8'(string)
Returns:
- (string)
Example:
use Bayfront\StringHelpers\Str; $string = 'This is a string.'; echo Str::titleCase($string);
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
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
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
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): AnyRANDOM_TYPE_*constant)
Valid $type constants include:
RANDOM_TYPE_NONZERORANDOM_TYPE_NUMERICRANDOM_TYPE_ALPHA: Alphabetic, upper and lowercaseRANDOM_TYPE_ALPHA_LOWERRANDOM_TYPE_ALPHA_UPPERRANDOM_TYPE_ALPHANUMERIC: Alphanumeric, upper and lowercaseRANDOM_TYPE_ALPHANUMERIC_LOWERRANDOM_TYPE_ALPHANUMERIC_UPPERRANDOM_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
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
Description:
Return a UUID v4 string.
Parameters:
- (None)
Returns:
- (string)
Example:
use Bayfront\StringHelpers\Str; echo Str::uuid4();
uuid7
Description:
Return a lexicographically sortable UUID v7 string.
Parameters:
- (None)
Returns:
- (string)
Example:
use Bayfront\StringHelpers\Str; echo Str::uuid7();
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
Description:
Convert 16 byte binary string to UUID.
Parameters:
$binary(string)
Returns:
- (string)
Example:
use Bayfront\StringHelpers\Str; $uuid = Str::binToUuid($binary);
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
Description:
Verify input string has a specified complexity.
Parameters:
$string(string)$min_length(int)$max_length(int):0for 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
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
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
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
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
Description:
Return a UUID v4 string.
This method has been depreciated in favor of Str::uuid4 and Str::uuid7.
Parameters:
- (None)
Returns:
- (string)
Example:
use Bayfront\StringHelpers\Str; echo Str::uuid();
bayfrontmedia/php-string-helpers 适用场景与选型建议
bayfrontmedia/php-string-helpers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.77k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「helpers」 「function」 「string」 「helper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bayfrontmedia/php-string-helpers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bayfrontmedia/php-string-helpers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bayfrontmedia/php-string-helpers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHPUnit extension to Mock PHP internal functions using Runkit.
A lite function pack for PHP.
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
PostgreSQL ROUND() function for Doctrine ORM
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
HTML and form generation
统计信息
- 总下载量: 3.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-27