hugsbrugs/php-string

此包最新版本(1.2)没有可用的许可证信息。

PHP 字符串工具

1.2 2022-04-04 10:56 UTC

This package is auto-updated.

Last update: 2024-09-04 16:10:24 UTC


README

这个库提供了简化字符串操作的功能函数。

Build Status Coverage Status

安装

使用 composer 安装包

composer require hugsbrugs/php-string

在您的 PHP 代码中加载库

require_once __DIR__ . '/../vendor/autoload.php';
use Hug\HString\HString as HString;

注意:我不能使用 String 作为命名空间,因为它是一个 PHP 保留字,因此命名空间是 HString ...

用法

替换字符串的最后一个出现位置

$string = HString::str_replace_last($search, $replace, $subject);

检查字符串是否以指定的字符开头

$bool = HString::starts_with($haystack, $needle);

检查字符串是否以指定的字符结尾

$bool = HString::ends_with($haystack, $needle);

检查字符串是否包含 utf8mb4 字符(4字节编码的字符)

$bool = HString::is_utf8mb4($search);

单元测试

phpunit --bootstrap vendor/autoload.php tests

作者

Hugo Maugey 访问我的网站 ;)