Str
in package
Table of Contents
Properties
- $size : mixed
Methods
- cut() : string
- 截取后,用 ...代替被截取的部分
- dis() : string
- 500m 1km 1公里
- discount() : string
- 折扣 100 1 0.1折
- less_time() : array<string|int, mixed>
- 计算时间剩余
- order_id() : mixed
- 生成订单号,唯一的 $id = \lib\Str::order_id('SP');
- rand() : string
- 随机字符
- rand_number() : int
- 随机数字
- size() : string
- 字节单位自动转换 显示1GB MB等
- size_to() : string
- 字节单位自动转换到指定的单位
- sony_flake_id() : mixed
- 使用Sonyflake生成唯一值,确保并发时生成唯一ID,最长可用174年 $id = \lib\Str::sony_flake_id(); 如果需要不同的sequence,可传值\lib\Str::sony_flake_id($center_id=0,$work_id=1); config.ini.php $config['redis'] = [ 'host'=>'', 'port'=>'', 'auth'=>'', ];
- uuid() : mixed
- 生成UUID https://uuid.ramsey.dev/en/stable/quickstart.html#using-ramsey-uuid
Properties
$size
public
static mixed
$size
= ['B', 'KB', 'MB', 'GB', 'TB']
Methods
cut()
截取后,用 ...代替被截取的部分
public
static cut(string $string, int $length[, mixed $append = '' ]) : string
Parameters
- $string : string
-
字符串
- $length : int
-
截取长度
- $append : mixed = ''
Return values
stringdis()
500m 1km 1公里
public
static dis(mixed $dis) : string
Parameters
- $dis : mixed
-
[description]
Return values
string —[description]
discount()
折扣 100 1 0.1折
public
static discount(mixed $price, mixed $nowprice) : string
Parameters
- $price : mixed
- $nowprice : mixed
Return values
stringless_time()
计算时间剩余
public
static less_time( $timestamp[, $small_timestamp = null ]) : array<string|int, mixed>
$timestamp - $small_timestamp 剩余的时间,相差几天几小时几分钟
Parameters
Return values
array<string|int, mixed> —2天3小时28分钟10秒
order_id()
生成订单号,唯一的 $id = \lib\Str::order_id('SP');
public
static order_id([mixed $prefix = '' ][, mixed $center_id = 0 ][, mixed $work_id = 0 ]) : mixed
Parameters
- $prefix : mixed = ''
- $center_id : mixed = 0
- $work_id : mixed = 0
rand()
随机字符
public
static rand([string $j = 8 ]) : string
Parameters
- $j : string = 8
-
位数
Return values
stringrand_number()
随机数字
public
static rand_number([string $j = 4 ]) : int
Parameters
- $j : string = 4
-
位数
Return values
intsize()
字节单位自动转换 显示1GB MB等
public
static size(string $size) : string
Parameters
- $size : string
Return values
stringsize_to()
字节单位自动转换到指定的单位
public
static size_to(string $size[, string $to = 'GB' ]) : string
Parameters
- $size : string
- $to : string = 'GB'
Return values
stringsony_flake_id()
使用Sonyflake生成唯一值,确保并发时生成唯一ID,最长可用174年 $id = \lib\Str::sony_flake_id(); 如果需要不同的sequence,可传值\lib\Str::sony_flake_id($center_id=0,$work_id=1); config.ini.php $config['redis'] = [ 'host'=>'', 'port'=>'', 'auth'=>'', ];
public
static sony_flake_id([mixed $center_id = 0 ][, mixed $work_id = 0 ]) : mixed
$config['sony_flake'] = [ 'from_date'=>'2022-10-27', ]; https://github.com/godruoyi/php-snowflake
Parameters
- $center_id : mixed = 0
- $work_id : mixed = 0
uuid()
生成UUID https://uuid.ramsey.dev/en/stable/quickstart.html#using-ramsey-uuid
public
static uuid([mixed $int = 4 ]) : mixed
Parameters
- $int : mixed = 4