Home > Backend Development > PHP Tutorial > Summary of ThinkPHP string functions and commonly used functions

Summary of ThinkPHP string functions and commonly used functions

不言
Release: 2023-03-30 06:56:01
Original
2143 people have browsed it

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()
Copy after login

Get the client’s IP address

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

$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}
Copy after login

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='')
Copy after login

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)
Copy after login

Create random verification code, mode parameter usage and rand_string type Consistent

byte_format(size, dec=2)
Copy after login

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

is_utf8(string)
Copy after login

Detect whether the string is utf8 encoded

highlight_code(str,show=false)
Copy after login

Code highlighting

h(text, tags = null)
Copy after login

Output safe Html code

ubb(Text)
Copy after login

Basic UBB parsing

build_count_rand (number,length=4,mode=1)
Copy after login

Randomly generate a set of strings

remove_xss(val)
Copy after login

Remove XSS attacks in Html code

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

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')
Copy after login

. 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)
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template