class StrHelper

字串处理

Methods

array
mdToc(string $content)

获取 markdown 索引

static string
suffix(string $string, string $split = '.')

获取文件名后缀名

static array|string|string[]
slug(string $string)

获取中杠线分割的单词

static string
prefix(string $string, string $split = '.')

获取文件名前缀

static int
hasSpace(string $value)

检测是否含有空格符

static array|string
stripSlashes(mixed $input)

取消转义

static array|string
addSlashes(mixed $input)

转义操作

static array|mixed|string
htmlSpecialChars(mixed $input, bool $preserveAmpersand = true)

转义特殊字符

static array|mixed
safe(mixed $input)

能做到代码不危害大众, 但是还不能把代码安全展示出来

static mixed
trimEOL(string $string, bool $js = false)

删除代码中的换行符

static string
trimSpace(string $string)

去除空格, 换行

static mixed|string
cut(string $string, int $length, string $suffix = '', int $start = 0, string $char_code = 'utf-8')

截取字符串

static string
toHex(string $str)

文字 -> 16进制表示

static string
fromHex(string $hex)

16进制转换为字串

static string
randomCustom(int $length, string $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz')

返回随机字串, 区分大小写

static string
randomAscii(int $length = 8)

随机ASCII字符

static string
randomNumber(int $min, int $max)

获取一定范围内的随机数字 位数不足补零

static array|string
convert(string $str, string $fromCharset = 'utf-8', string $toCharset = 'gbk')

转换字符

static array
batchConvert(mixed $str, string $fromCharset = 'utf-8', string $toCharset = 'gbk')

批量转换

static string
ch2Utf8(string $char)

中文->Utf8

static int
count(mixed $string)

计算字符长度

static int
isUtf8(string $str)

检测字符是否为UTF8编码

static string
chrysanthemum(string $str)

菊花文生成

static string
jsEscape(string $str)

JS 转义函数

static array
separate(string $separator, string $str)

分割 separate, 去除空格

static mixed
parseKey(mixed $str)

解析 a|1;b|2 样式的字串到数组

static string
matchEncode(mixed $ids)

sql against encode

static array|mixed
matchDecode(mixed $ids, bool|false $array = false)

reverse for match

static string
hideContact(string $input, int $start = 3, int $end = -4, string $replace = '****')

隐藏联系方式

static string
hideEmail(string $input)

隐藏邮箱

static string
ordinal(int $number)

Converts number to its ordinal English form.

static mixed
normalizeEol(string $string)

Converts line breaks to a standard \r\n pattern.

static string
normalizeClassName(mixed $name)

Removes the starting slash from a class namespace \

static string
getClassId(mixed $name)

从对象或者类名中生成 class id

static bool|string
getClassNamespace(string $name)

返回一个类的命名空间

static mixed
clearLink(string $content)

清除链接

static string
fixLink(string $url)

完善链接

static mixed|string
intro(string $content, int $length = 0)

将内容截取到介绍中

static string|string[]
formatId(string|string[] $string)

格式化ID

static mixed
unique(string $current, string $str, string $delimiter = ',', bool $remove = false)

返回唯一的值

Details

at line 20
array mdToc(string $content)

获取 markdown 索引

Parameters

string $content content

Return Value

array

at line 73
static string suffix(string $string, string $split = '.')

获取文件名后缀名

Parameters

string $string string
string $split split

Return Value

string

at line 83
static array|string|string[] slug(string $string)

获取中杠线分割的单词

Parameters

string $string

Return Value

array|string|string[]

at line 94
static string prefix(string $string, string $split = '.')

获取文件名前缀

Parameters

string $string string
string $split string

Return Value

string

at line 104
static int hasSpace(string $value)

检测是否含有空格符

Parameters

string $value value

Return Value

int

at line 114
static array|string stripSlashes(mixed $input)

取消转义

Parameters

mixed $input input

Return Value

array|string

at line 124
static array|string addSlashes(mixed $input)

转义操作

Parameters

mixed $input input

Return Value

array|string

at line 135
static array|mixed|string htmlSpecialChars(mixed $input, bool $preserveAmpersand = true)

转义特殊字符

Parameters

mixed $input input
bool $preserveAmpersand preserveAmpersand

Return Value

array|mixed|string

at line 160
static array|mixed safe(mixed $input)

能做到代码不危害大众, 但是还不能把代码安全展示出来

Parameters

mixed $input input

Return Value

array|mixed

at line 187
static mixed trimEOL(string $string, bool $js = false)

删除代码中的换行符

Parameters

string $string string
bool $js js

Return Value

mixed

at line 199
static string trimSpace(string $string)

去除空格, 换行

Parameters

string $string string

Return Value

string

at line 215
static mixed|string cut(string $string, int $length, string $suffix = '', int $start = 0, string $char_code = 'utf-8')

截取字符串

Parameters

string $string 带截取的字符串
int $length 长度
string $suffix 后缀
int $start 开始字符
string $char_code

Return Value

mixed|string 中文截断字符方法

at line 283
static string toHex(string $str)

文字 -> 16进制表示

Parameters

string $str str

Return Value

string

at line 293
static string fromHex(string $hex)

16进制转换为字串

Parameters

string $hex hex

Return Value

string

at line 313
static string randomCustom(int $length, string $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz')

返回随机字串, 区分大小写

Parameters

int $length length
string $chars chars

Return Value

string

at line 329
static string randomAscii(int $length = 8)

随机ASCII字符

Parameters

int $length length

Return Value

string

at line 345
static string randomNumber(int $min, int $max)

获取一定范围内的随机数字 位数不足补零

Parameters

int $min 最小值
int $max 最大值

Return Value

string

at line 357
static array|string convert(string $str, string $fromCharset = 'utf-8', string $toCharset = 'gbk')

转换字符

Parameters

string $str str
string $fromCharset fromCharset
string $toCharset toCharset

Return Value

array|string

at line 405
static array batchConvert(mixed $str, string $fromCharset = 'utf-8', string $toCharset = 'gbk')

批量转换

Parameters

mixed $str str
string $fromCharset fromCharset
string $toCharset toCharset

Return Value

array

at line 426
static string ch2Utf8(string $char)

中文->Utf8

Parameters

string $char char

Return Value

string

at line 456
static int count(mixed $string)

计算字符长度

Parameters

mixed $string string

Return Value

int

at line 475
static int isUtf8(string $str)

检测字符是否为UTF8编码

Parameters

string $str str

Return Value

int

at line 494
static string chrysanthemum(string $str)

菊花文生成

Parameters

string $str str

Return Value

string

at line 516
static string jsEscape(string $str)

JS 转义函数

Parameters

string $str str

Return Value

string

at line 527
static array separate(string $separator, string $str)

分割 separate, 去除空格

Parameters

string $separator separator
string $str str

Return Value

array

at line 549
static mixed parseKey(mixed $str)

解析 a|1;b|2 样式的字串到数组

Parameters

mixed $str str

Return Value

mixed

at line 582
static string matchEncode(mixed $ids)

sql against encode

Parameters

mixed $ids ids

Return Value

string

at line 597
static array|mixed matchDecode(mixed $ids, bool|false $array = false)

reverse for match

Parameters

mixed $ids ids
bool|false $array array

Return Value

array|mixed

at line 620
static string hideContact(string $input, int $start = 3, int $end = -4, string $replace = '****')

隐藏联系方式

Parameters

string $input 输入内容
int $start 开始位数
int $end 结束位数
string $replace 替换字串

Return Value

string

at line 633
static string hideEmail(string $input)

隐藏邮箱

Parameters

string $input input

Return Value

string

at line 649
static string ordinal(int $number)

Converts number to its ordinal English form.

This method converts 13 to 13th, 2 to 2nd ...

Parameters

int $number

Number to get its ordinal value

Return Value

string

ordinal representation of given string

at line 672
static mixed normalizeEol(string $string)

Converts line breaks to a standard \r\n pattern.

Parameters

string $string string

Return Value

mixed

at line 682
static string normalizeClassName(mixed $name)

Removes the starting slash from a class namespace \

Parameters

mixed $name name

Return Value

string

at line 698
static string getClassId(mixed $name)

从对象或者类名中生成 class id

Parameters

mixed $name name

Return Value

string

at line 714
static bool|string getClassNamespace(string $name)

返回一个类的命名空间

Parameters

string $name name

Return Value

bool|string

清除链接

Parameters

string $content content

Return Value

mixed

完善链接

Parameters

string $url url

Return Value

string

at line 751
static mixed|string intro(string $content, int $length = 0)

将内容截取到介绍中

Parameters

string $content 有待截取的内容
int $length 带截取的长度

Return Value

mixed|string 截取内容的一部分

at line 770
static string|string[] formatId(string|string[] $string)

格式化ID

Parameters

string|string[] $string

Return Value

string|string[]

at line 783
static mixed unique(string $current, string $str, string $delimiter = ',', bool $remove = false)

返回唯一的值

Parameters

string $current current
string $str str
string $delimiter delimiter
bool $remove remove

Return Value

mixed