ThinkPHP/Extend/Functionextend.php

Think扩展函数库 需要手动加载后调用或者放入项目函数库

Functions

msubstr()

msubstr(string  $str, string  $start, string  $length, string  $charset = "utf-8", string  $suffix = true) : string

字符串截取,支持中文和其他编码

Parameters

string $str

需要转换的字符串

string $start

开始位置

string $length

截取长度

string $charset

编码格式

string $suffix

截断显示字符

Returns

string

rand_string()

rand_string(string  $len = 6, string  $type = '', string  $addChars = '') : string

产生随机字串,可用来自动生成密码 默认长度6位 字母和数字混合

Parameters

string $len

长度

string $type

字串类型 0 字母 1 数字 其它 混合

string $addChars

额外字符

Returns

string

build_verify()

build_verify(  $length = 4,   $mode = 1) : string

获取登录验证码 默认为4位数字

Parameters

$length
$mode

Returns

string

byte_format()

byte_format(  $size,   $dec = 2) : string

字节格式化 把字节数格式为 B K M G T 描述的大小

Parameters

$size
$dec

Returns

string

is_utf8()

is_utf8(string  $string) : Boolean

检查字符串是否是UTF8编码

Parameters

string $string

字符串

Returns

Boolean

highlight_code()

highlight_code(String  $str, Boolean  $show = false) : String

代码加亮

Parameters

String $str

要高亮显示的字符串 或者 文件名

Boolean $show

是否输出

Returns

String

h()

h(  $text,   $tags = null) 

Parameters

$text
$tags

ubb()

ubb(  $Text) 

Parameters

$Text

build_count_rand()

build_count_rand(  $number,   $length = 4,   $mode = 1) 

Parameters

$number
$length
$mode

remove_xss()

remove_xss(  $val) 

Parameters

$val

list_to_tree()

list_to_tree(array  $list,   $pk = 'id', string  $pid = 'pid',   $child = '_child',   $root) : array

把返回的数据集转换成Tree

Parameters

array $list

要转换的数据集

$pk
string $pid

parent标记字段

$child
$root

Returns

array

list_sort_by()

list_sort_by(array  $list, string  $field, array  $sortby = 'asc') : array

对查询结果集进行排序

Parameters

array $list

查询结果

string $field

排序的字段名

array $sortby

排序类型 asc正向排序 desc逆向排序 nat自然排序

Returns

array

list_search()

list_search(array  $list, mixed  $condition) : array

在数据列表中搜索

Parameters

array $list

数据列表

mixed $condition

查询条件 支持 array('name'=>$value) 或者 name=$value

Returns

array

auto_charset()

auto_charset(  $fContents,   $from = 'gbk',   $to = 'utf-8') 

Parameters

$fContents
$from
$to