thinkphp string function and general function summary

Source: Internet
Author: User
This article mainly introduces the thinkphp string function and common function Summary, can be used by the developer reference, the need for friends can refer to the following

This article summarizes the string-handling functions of thinkphp and other common functions that 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: the 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: If an ellipsis is displayed after the truncated character, the default is true to show that 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, encode as UTF-8, do 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 Lowercase Letter 4 Chinese 5 Mix (remove easily confusing characters Ooll and number 01)
Addchars attached string

Build_verify (length=4,mode=1)

Create a random verification code, the mode parameter usage is consistent with the type of rand_string

Byte_format (size, dec=2)

Byte formatting the easy-to-understand size described by the byte number format as B K M G T

Is_utf8 (String)

Detects if a string is UTF8 encoded

Highlight_code (Str,show=false)

Code highlighting

H (text, tags = null)

Output Secure HTML code

UBB (Text)

Basic UBB Analysis

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)

The data set of the query is converted into a tree list array, the list represents the data set (array) of the query, PK denotes the primary key name, the PID represents the parent key name, the child represents the name of the sub-list, and the default is the _child,root represents the primary key value of the node.

List_sort_by (List,field, sortby= ' ASC ')

Sort the dataset for 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 ASC

List_ Search (list,condition)

Search data in the query DataSet, list represents the result DataSet (array) of the query, condition represents the query criteria, support the following query methods
Array mode 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)

Sends HTTP status information, status indicates HTTP status value, for example 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.