字符串处理,大部分为原 ginkgo\Func
类迁移而来
0.2.0
新增 ginkgo\String
0.2.1
更名为 ginkgo\Strings
namespace ginkgo;
class Strings {
// 方法
public static ucwords( string $str [, string $delimiter ] ) : string
public static toHump( string $str [, string $delimiter [, bool $lcfirst = false ]] ) : string
public static toLine( string $str [, string $delimiter ] ) : string
public static sizeFormat( numeric $size [, int $float = 2 ] ) : string
public static numFormat( numeric $num [, int $float = 2 ] ) : string
public static secrecy( string $string [, int $left = 5 [, int $right = 5 [, string $hide = '*' ]]] ) : string
public static toBase64( string $string [, bool $url_safe = true ] ) : string
public static fromBase64( string $base64code [, bool $url_safe = true ] ) : string
// 已迁移方法
public static toTime( string $datetime ) : int
}
- | 权限 | 类型 | 描述 |
---|---|---|---|
方法 | - | - | - |
ucwords() | public | static | 将字符串中每个单词的首字母转换为大写 |
toTime() | public | static | 日期时间字符串转时间戳 |
toHump() | public | static | 以指定的分隔符将字符串转换为驼峰写法 |
toLine() | public | static | 将驼峰写法的字符串转换为小写加分隔符 |
sizeFormat() | public | static | 文件大小格式化 |
numFormat() | public | static | 格式化数字 |
secrecy() | public | static | 隐藏敏感信息 |
toBase64() | public | static | 转换为 Base64 |
fromBase64() | public | static | Base64 转换为字符串 |
ucwords()
将字符串中每个单词的首字母转换为大写public static function ucwords( string $str [, string $delimiter = "\t\r\n\f\v" ] ) : string
参数
str
字符串delimiter
单词分割字符返回
toTime()
日期时间字符串转时间戳0.2.5
起迁移至 ginkgo/Datetime
public static function toTime( string $datetime ) : int
参数
datetime
日期时间字符串返回
toHump()
以指定的分隔符将字符串转换为驼峰写法public static function toHump( string $str [, string $delimiter [, bool $lcfirst = false ]] ) : string
参数
str
字符串delimiter
单词分割字符lcfirst
是否首字母小写返回
toLine()
将驼峰写法的字符串转换为小写加分隔符public static function toLine( string $str [, string $delimiter ] ) : string
参数
str
字符串delimiter
单词分割字符返回
sizeFormat()
文件大小格式化public static function sizeFormat( numeric $size [, int $float = 2 ] ) : string
参数
size
文件大小float
保留小数位数返回
numFormat()
格式化数字public static function numFormat( numeric $num [, int $float = 2 ] ) : string
参数
num
数字float
保留小数位数返回
secrecy()
隐藏敏感信息用于敏感字符的隐藏,如手机号码:139 **** 8888
public static function secrecy( string $string [, int $left = 5 [, int $right = 5 [, string $hide = '*' ]]] ) : string
参数
string
字符串left
保留左侧字符个数right
保留右侧字符个数hide
替代字符返回
toBase64()
转换为 Base64public static function toBase64( string $string [, bool $url_safe = true ] ) : string
参数
string
数组url_safe
是否已 URL 安全的方式编码
说明
由于默认 Base64 编码结果中有部分字符与 URL 规则冲突,当 url_safe
为 true 时,会将编码结果中的 + 替换为 -、/ 替换为 _、= 将被剔除,以保证编码结果通过 URL 传递时的安全。
返回
fromBase64()
Base64 转换为字符串public static function fromBase64( string $base64code [, bool $url_safe = true ] ) : string
参数
base64code
数组url_safe
是否已 URL 安全的方式解码
说明
如果 base64code
是通过 URL 安全的方式进行编码的,那么必须采用 URL 安全的方式解码,否则将会出错。
返回