Home  >  Article  >  Backend Development  >  ThinkPHP字符串函数及常用函数汇总_PHP

ThinkPHP字符串函数及常用函数汇总_PHP

WBOY
WBOYOriginal
2016-06-01 11:50:191143browse

本文汇总了ThinkPHP的字符串处理函数及其他一些常用函数,可供开发人员参考使用。详情如下:

get_client_ip() 

获取客户端的IP地址

msubstr($str, $start=0, $length, $charset=”utf-8″, $suffix=true)

$str:要截取的字符串
$start=0:开始位置,默认从0开始
$length:截取长度
$charset=”utf-8″:字符编码,默认UTF-8
$suffix=true:是否在截取后的字符后面显示省略号,默认true显示,false为不显示

中文字符串截取:

调用如下

{$vo.title|msubstr=5,5,'utf-8′,false}

解释:截取字符串$vo.title,从第5个字符开始,截取5个,编码为UTF-8,不显示省略号

rand_string(len=6,type='',addChars='') 

产生随机字串
type是随机类型,包括:
0 字母 1 数字 2 大写字母 3 小写字母 4中文 5混合(去掉了容易混淆的字符oOLl和数字01)
addChars 附加的字符串

build_verify (length=4,mode=1) 

创建随机验证码,mode参数用法和rand_string的type一致

byte_format(size, dec=2) 

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

is_utf8(string) 

检测字符串是否是utf8编码

highlight_code(str,show=false) 

代码高亮

h(text, tags = null) 

输出安全的Html代码

ubb(Text) 

基本的UBB解析

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

随机生成一组字符串

remove_xss(val) 

移除Html代码中的XSS攻击

list_to_tree(list, pk='id',pid = 'pid',child = '_child',root=0) 

把查询的数据集转换成树形列表数组, list表示查询的数据集(数组),pk表示主键名,pid表示父键名,child表示子列表的名称,默认是_child,root表示跟节点的主键值

list_sort_by(list,field, sortby='asc') 

对查询的数据集排序,list表示查询的结果数据集(数组),field表示要排序的字段名称,sortby表示排序类型,包括asc正向排序 desc逆向排序 nat自然排序,默认为asc

list_ search(list,condition) 

在查询的数据集中搜索数据,list表示查询的结果数据集(数组),condition表示查询条件,支持支持下面的查询方式
数组方式如 array('var1'=>'value1', 'var2'=>'value2') 并且支持正则表达式array('name'=>'/[A-Z]/')
URL方式如var1=value1&var2=value2

send_http_status(status) 

发送http状态信息,status表示http状态值,例如302、404

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn