Home > Backend Development > PHP Tutorial > Thinkphp模板中截取字符串函数简介_PHP

Thinkphp模板中截取字符串函数简介_PHP

WBOY
Release: 2016-06-01 11:51:01
Original
958 people have browsed it

ThinkPHP

在php中截取字符串的函数有很多,而在thinkphp中也可以直接使用php的函数,本文给大家简单的介绍thinkPHP模板中截取字符串的具体用法,希望能对各位有所帮助。

对于英文字符可使用如下形式:

复制代码 代码如下:
{$vo.title|substr=0,5}

如果是中文字符thinkphp提供了msubstr,用法如下:

复制代码 代码如下:
function msubstr($str, $start=0, $length, $charset=”utf-8″, $suffix=true)//使用如下
{$vo.title|msubstr=5,5,'utf-8′,true}

其中msubstr函数说明如下:

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

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