lag / string-utils
PHP类,用于帮助字符串操作
v1.2
2019-08-21 18:50 UTC
Requires
- php: ^7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- phpunit/phpunit: ^7.0 || ^8.2
This package is auto-updated.
Last update: 2024-08-29 05:00:49 UTC
README
string-utils
string-utils是一个静态PHP类,用于帮助字符串操作。它添加了提取字符串的开始或结束部分的方法,测试字符串是否以其他字符串开头或结尾,以及将字符串转换为驼峰格式或下划线格式。
安装
composer require lag/string-utils
使用方法
返回字符串的开始或结束部分
<?php use LAG\Component\StringUtils\StringUtils; StringUtils::start('War of Stars', 3); // War StringUtils::end('War of Stars', 3); // ars
测试字符串的开始或结束部分
<?php use LAG\Component\StringUtils\StringUtils; StringUtils::endsWith('Jedi', 'i'); // true StringUtils::endsWith('Jedi', 'edi'); // true StringUtils::endsWith('Jedi', 'Sith'); // false StringUtils::endsWith('Jedi', 'S'); // false StringUtils::startsWith('Laser', 'L'); // true StringUtils::startsWith('Laser', 'Las'); // true StringUtils::startsWith('Laser', 'Force'); // false StringUtils::startsWith('Laser', 'F'); // false
将字符串转换为驼峰格式或下划线格式
<?php use LAG\Component\StringUtils\StringUtils; StringUtils::camelize('my little jedi'); // returns MyLittleJedi StringUtils::underscore('my little jedi'); // returns my_little_jedi