Home>Article>Backend Development> Summary of ThinkPHP string functions and commonly used functions
This article mainly introduces ThinkPHP string functions and a summary of commonly used functions, which can be used as a reference for developers. Friends who need it can refer to it
This article summarizes ThinkPHP's string processing functions and some other commonly used functions. function for reference by developers. The details are as follows:
get_client_ip()
Get the client’s IP address
msubstr($str, $start=0, $length, $charset=”utf-8″, $suffix=true)
$str: Required Intercepted string
$start=0: starting position, default starts from 0
$length: intercepted length
$charset=”utf-8″: character encoding, default UTF-8
$ suffix=true: Whether to display an ellipse after the intercepted character, the default is true to display, false to not display
Chinese string interception:
Call as follows
{$vo.title|msubstr=5,5,'utf-8′,false}
Explanation: Intercept the string $vo.title, starting from the 5th character, intercept 5 characters, encode them as UTF-8, and do not display the ellipses
rand_string(len=6,type='',addChars='')
Generate a random string
type is a random type, including:
0 letter 1 number 2 uppercase letter 3 lowercase letter 4 Chinese 5 mixed ( Removed the easily confused characters oOLl and numbers 01)
addChars additional string
build_verify (length=4,mode=1)
Create random verification code, mode parameter usage and rand_string type Consistent
byte_format(size, dec=2)
Byte formatting formats the number of bytes as an easy-to-understand size described by B K M G T
is_utf8(string)
Detect whether the string is utf8 encoded
highlight_code(str,show=false)
Code highlighting
h(text, tags = null)
Output safe Html code
ubb(Text)
Basic UBB parsing
build_count_rand (number,length=4,mode=1)
Randomly generate a set of strings
remove_xss(val)
Remove XSS attacks in Html code
list_to_tree(list, pk='id',pid = 'pid',child = '_child',root=0)
Convert the queried data set into a tree list array. list represents the queried data set (array), pk represents the primary key name, pid represents the parent key name, and child represents the name of the child list. The default is _child, and root represents Sort the queried data set according to the primary key value of the node
list_sort_by(list,field, sortby='asc')
. List represents the query result data set (array), and field represents the name of the field to be sorted. , sortby represents the sorting type, including asc forward sorting desc reverse sorting nat natural sorting, the default is asc
list_ search(list,condition)
Search for data in the queried data set, list represents The query result data set (array), condition represents the query condition, and supports the following query methods
Array method such as array('var1'=>'value1', 'var2'=>'value2') and supports Regular expression array('name'=>'/[A-Z]/')
URL method such as var1=value1&var2=value2
send_http_status(status)
Send http status information, status represents http status value, such as 302, 404
Related recommendations:
ThinkPHP implements simple login function
The above is the detailed content of Summary of ThinkPHP string functions and commonly used functions. For more information, please follow other related articles on the PHP Chinese website!