Summary of ThinkPHP String Functions and Commonly Used Functions

  • 2021-07-09 07:17:59
  • OfStack

This article summarizes the string processing functions of ThinkPHP and other common functions, which can be used for reference by developers. 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, starting from 0 by default
$length: Intercept length
$charset= "utf-8": Character encoding, default UTF-8
$suffix=true: Whether to display ellipsis after truncated characters, the default is true, and false is not displayed

Chinese string interception:

Call the following

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

Explanation: Intercept the string $vo. title, starting with the 5th character, intercept 5 characters, encode as UTF-8, and do not show ellipsis


Generate random strings
type is a random type and includes:
0 letter 1 number 2 uppercase letter 3 lowercase letter 4 Chinese character 5 mixed (remove the confusing character oOLl and number 01)
addChars attached string

build_verify (length=4,mode=1) 

Create random verification code, mode parameter usage and type1 to rand_string

byte_format(size, dec=2) 

Byte formatting formats the number of bytes to an easy-to-understand size described by B K M G T


Detect whether the string is utf8 encoded


Code highlighting

h(text, tags = null) 

Output secure Html code


Basic UBB parsing

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

Randomly generate 1 set of strings

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

Remove XSS attack from Html code

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

The queried dataset is converted into a tree list array, list denotes the queried dataset (array), pk denotes the primary key name, pid denotes the parent key name, child denotes the name of the child list, the default is _ child, root denotes the primary key value of the following node

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

Sort the query dataset, list denotes the query result dataset (array), field denotes the field name to be sorted, sortby denotes the sort type, including asc forward sort, desc reverse sort, nat natural sort, and the default is asc

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

Searching for data in the query dataset, list denotes the query result dataset (array), condition denotes the query condition, and supports the following query methods
Array mode such as array ('var1' = > 'value1', 'var2'= > 'value2') and supports the regular expression array ('name' = > '/[A-Z]/')
URL mode such as var1=value1 & var2=value2

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

Sending http status information, status representing http status values, e.g. 302, 404

Related articles: