This article summarizes the string processing functions of thinkphp and other common functions, which can be used by developers for reference. Details are as follows:
Get the IP address of the client
Msubstr ($str, $start =0, $length, $charset = "Utf-8″, $suffix =true)
$STR: String to intercept
$start = 0: Start position, default starting from 0
$length: Intercept length
$charset = "Utf-8″: Character encoding, default UTF-8
$suffix =true: Whether to display the ellipsis after the intercepted character, the default true, False to not show
Chinese string interception:
Call the following
{$vo. title|msubstr=5,5, ' Utf-8′,false}
Explanation: Intercepts the string $vo.title, starts from the 5th character, intercepts 5, encodes as UTF-8, does not display the ellipsis
Rand_string (len=6,type= ', addchars= ')
Generate Random strings
Type is random, including:
0 Letter 1 Digit 2 Capital Letter 3 Small Letter 4 Chinese 5 mixed (removed easily confusing characters Ooll and number 01)
Addchars Strings Attached
Build_verify (length=4,mode=1)
Create random CAPTCHA, mode parameter usage is consistent with rand_string type
Byte_format (size, dec=2)
Byte format is an easy to understand size that is described in byte number format B K M G T
Detects whether a string is a UTF8 encoding
Highlight_code (Str,show=false)
Code highlighting
Export Secure HTML code
Basic UBB Parsing
Build_count_rand (number,length=4,mode=1)
Randomly generating a set of strings
Remove XSS attacks in HTML code
List_to_tree (list, pk= ' id ', pid = ' pid ', child = ' _child ', root=0)
The query's dataset is converted to a tree-list array, the list represents the data set (array) of the query, PK represents the primary key, the PID is the parent key, the child is the name of the sub list, and the default is the _child,root representing the primary key value of the node.
List_sort_by (List,field, sortby= ' ASC ')
Sort the data set of the query, list represents the result DataSet (array) of the query, field represents the name of the fields to sort, sortby represents the sort type, including ASC forward sort desc Reverse sort Nat Natural Sort, default to ASC
List_ Search (list,condition)
Search for data in the query's dataset, the list represents the result DataSet (array) of the query, condition represents the query criteria, and supports the following query methods
Array methods such as Array (' var1 ' => ' value1 ', ' var2 ' => ' value2 ') and support for regular expression array (' name ' => '/[a-z]/')
URL way like var1=value1&var2=value2
Send_http_status (status)
Sends HTTP status information, status represents HTTP status values, such as 302, 404