thinkphp string function and common function summary _php instance

Source: Internet
Author: User

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_CLIENT_IP () 

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

Is_utf8 (String) 

Detects whether a string is a UTF8 encoding

Highlight_code (Str,show=false) 

Code highlighting

H (text, tags = null) 

Export Secure HTML code

UBB (Text) 

Basic UBB Parsing

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

Randomly generating 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) 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.