ThinkPHP string functions and common functions

Source: Internet
Author: User
This article mainly introduces ThinkPHP string functions and common functions for reference by developers.

This article mainly introduces ThinkPHP string functions and common functions for reference by developers.

This article summarizes ThinkPHP string processing functions and some other common functions for developers to refer to and use. The details are as follows:

Get_client_ip ()

Obtain the Client IP Address

Msubstr ($ str, $ start = 0, $ length, $ charset = "UTF-8", $ suffix = true)

$ Str: string to be truncated
$ Start = 0: start position, starting from 0 by default
$ Length: truncation length
$ Charset = "UTF-8": character encoding, default UTF-8
$ Suffix = true: whether the ellipsis is displayed after the truncated characters. The default value is true, and false indicates that the ellipsis is not displayed.

Chinese string truncation:

The call is as follows:

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

Description: Truncated string $ vo. title, starting from 5th characters, intercepting 5, encoded as a UTF-8, not displaying ellipsis

Rand_string (len = 6, type = '', addChars = '')

Generate random string
Type is a random type, including:
0 letters, 1 digit, 2 capital letters, 3 lowercase letters, 4 Chinese characters, and 5 Characters in combination (remove confusing characters oOLl and numbers 01)
AddChars appended string

Build_verify (length = 4, mode = 1)

Create a Random verification code. The mode parameter is used in the same way as the rand_string type.

Byte_format (size, dec = 2)

Byte formatting the number of bytes is in the format of B K M G T, which is easy to understand.

Is_utf8 (string)

Checks whether the string is UTF-8 encoded.

Highlight_code (str, show = false)

Code highlighting

H (text, tags = null)

Output Secure Html code

Ubb (Text)

Basic UBB Parsing

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

Randomly generate a group of strings

Remove_xss (val)

Remove XSS attacks from Html code

List_to_tree (list, pk = 'id', pid = 'pid', child = '_ child', root = 0)

Converts the queried dataset into a tree list array. list indicates the queried dataset (array), pk indicates the primary key name, pid indicates the parent key name, and child indicates the sublist name, the default value is _ child. root indicates the primary key value of the node.

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

Sort the queried dataset. list indicates the queried result dataset (array), field indicates the name of the field to be sorted, and sortby indicates the sorting type, including asc forward sorting desc reverse sorting nat natural sorting, the default value is asc.

List _ search (list, condition)

Search for data in the queried dataset. list indicates the query result dataset (array) and condition indicates the query conditions. The following query methods are supported:
Array mode, such as array ('var1' => 'value1', 'var2' => 'value2 ') and supports the Regular Expression array ('name' => '/[A-Z]/')
The URL method is as follows: var1 = value1 & var2 = value2

Send_http_status (status)

Send http status information. status indicates the http status value, such as 302 and 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.