Search by

yangming / string-util

progincc

一个简单好用的PHP字符串处理工具包

v1.1.0 2026-07-24 02:57 UTC

This package is not auto-updated.

Last update: 2026-09-19 02:01:33 UTC


README

一个简单好用的PHP字符串处理工具,包含常用的字符串操作方法。

安装

composer require yangming/string-util

常用方法

use YangMing\StringUtil\StringHelper;

// 1. 判断开头/结尾
StringHelper::startsWith('hello world', 'hello'); // true
StringHelper::endsWith('hello world', 'world');   // true

// 2. 命名格式转换
StringHelper::toCamelCase('user_name');    // userName
StringHelper::toSnakeCase('userName');     // user_name

// 3. 数据脱敏
StringHelper::hidePhone('13800138000');    // 138****8000
StringHelper::maskEmail('test@example.com'); // te**@example.com

// 4. 生成随机字符串
StringHelper::random(8); // 随机8位字符串