Home php教程 php手册 ThinkPHP字符串函数及常用函数汇总

ThinkPHP字符串函数及常用函数汇总

Jun 06, 2016 pm 08:20 PM
thinkphp function Summary

这篇文章主要介绍了ThinkPHP字符串函数及常用函数汇总,可供开发人员参考使用,需要的朋友可以参考下

本文汇总了ThinkPHP的字符串处理函数及其他一些常用函数,可供开发人员参考使用。详情如下:

get_client_ip()

获取客户端的IP地址

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

$str:要截取的字符串
$start=0:开始位置,默认从0开始
$length:截取长度
$charset=”utf-8″:字符编码,默认UTF-8
$suffix=true:是否在截取后的字符后面显示省略号,默认true显示,false为不显示

中文字符串截取:

调用如下

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

解释:截取字符串$vo.title,从第5个字符开始,截取5个,,编码为UTF-8,不显示省略号

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

产生随机字串
type是随机类型,包括:
0 字母 1 数字 2 大写字母 3 小写字母 4中文 5混合(去掉了容易混淆的字符oOLl和数字01)
addChars 附加的字符串

build_verify (length=4,mode=1)

创建随机验证码,mode参数用法和rand_string的type一致

byte_format(size, dec=2)

字节格式化 把字节数格式为 B K M G T 描述的容易理解的大小

is_utf8(string)

检测字符串是否是utf8编码

highlight_code(str,show=false)

代码高亮

h(text, tags = null)

输出安全的Html代码

ubb(Text)

基本的UBB解析

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

随机生成一组字符串

remove_xss(val)

移除Html代码中的XSS攻击

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

把查询的数据集转换成树形列表数组, list表示查询的数据集(数组),pk表示主键名,pid表示父键名,child表示子列表的名称,默认是_child,root表示跟节点的主键值

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

对查询的数据集排序,list表示查询的结果数据集(数组),field表示要排序的字段名称,sortby表示排序类型,包括asc正向排序 desc逆向排序 nat自然排序,默认为asc

list_ search(list,condition)

在查询的数据集中搜索数据,list表示查询的结果数据集(数组),condition表示查询条件,支持支持下面的查询方式
数组方式如 array('var1'=>'value1', 'var2'=>'value2') 并且支持正则表达式array('name'=>'/[A-Z]/')
URL方式如var1=value1&var2=value2

send_http_status(status)

发送http状态信息,status表示http状态值,例如302、404

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Apr 21, 2024 am 10:21 AM

The advantages of default parameters in C++ functions include simplifying calls, enhancing readability, and avoiding errors. The disadvantages are limited flexibility and naming restrictions. Advantages of variadic parameters include unlimited flexibility and dynamic binding. Disadvantages include greater complexity, implicit type conversions, and difficulty in debugging.

What is the difference between custom PHP functions and predefined functions? What is the difference between custom PHP functions and predefined functions? Apr 22, 2024 pm 02:21 PM

The difference between custom PHP functions and predefined functions is: Scope: Custom functions are limited to the scope of their definition, while predefined functions are accessible throughout the script. How to define: Custom functions are defined using the function keyword, while predefined functions are defined by the PHP kernel. Parameter passing: Custom functions receive parameters, while predefined functions may not require parameters. Extensibility: Custom functions can be created as needed, while predefined functions are built-in and cannot be modified.

C++ Function Exception Advanced: Customized Error Handling C++ Function Exception Advanced: Customized Error Handling May 01, 2024 pm 06:39 PM

Exception handling in C++ can be enhanced through custom exception classes that provide specific error messages, contextual information, and perform custom actions based on the error type. Define an exception class inherited from std::exception to provide specific error information. Use the throw keyword to throw a custom exception. Use dynamic_cast in a try-catch block to convert the caught exception to a custom exception type. In the actual case, the open_file function throws a FileNotFoundException exception. Catching and handling the exception can provide a more specific error message.

Things to note when Golang functions receive map parameters Things to note when Golang functions receive map parameters Jun 04, 2024 am 10:31 AM

When passing a map to a function in Go, a copy will be created by default, and modifications to the copy will not affect the original map. If you need to modify the original map, you can pass it through a pointer. Empty maps need to be handled with care, because they are technically nil pointers, and passing an empty map to a function that expects a non-empty map will cause an error.

See all articles