解析smarty 截取字符串函数 truncate的用法介绍
程序员文章站
2022-12-28 08:52:53
smarty truncate 截取字符串从字符串开始处截取某长度的字符,默认的长度为80指定第二个参数作为截取字符串的长度默认情况下,smarty会截取到一个词的末尾,如...
smarty truncate 截取字符串
从字符串开始处截取某长度的字符,默认的长度为80
指定第二个参数作为截取字符串的长度
默认情况下,smarty会截取到一个词的末尾,
如果需要精确到截取多少个字符可以使用第三个参数,将其设为”true”
具体用法如下:
//index.php $smarty = new smarty;
$smarty->assign('articletitle', 'two sisters reunite after eighteen years at checkout counter.');
$smarty->display('index.tpl');
//index.tpl
{$articletitle}
{$articletitle|truncate}
{$articletitle|truncate:30}
{$articletitle|truncate:30:""}
{$articletitle|truncate:30:"---"}
{$articletitle|truncate:30:"":true}
{$articletitle|truncate:30:"...":true}
输出结果:
two sisters reunite after eighteen years at checkout counter.
two sisters reunite after eighteen years at checkout counter.
two sisters reunite after…
two sisters reunite after
two sisters reunite after—
two sisters reunite after eigh
two sisters reunite after e…
从字符串开始处截取某长度的字符,默认的长度为80
指定第二个参数作为截取字符串的长度
默认情况下,smarty会截取到一个词的末尾,
如果需要精确到截取多少个字符可以使用第三个参数,将其设为”true”
具体用法如下:
复制代码 代码如下:
//index.php $smarty = new smarty;
$smarty->assign('articletitle', 'two sisters reunite after eighteen years at checkout counter.');
$smarty->display('index.tpl');
//index.tpl
{$articletitle}
{$articletitle|truncate}
{$articletitle|truncate:30}
{$articletitle|truncate:30:""}
{$articletitle|truncate:30:"---"}
{$articletitle|truncate:30:"":true}
{$articletitle|truncate:30:"...":true}
输出结果:
two sisters reunite after eighteen years at checkout counter.
two sisters reunite after eighteen years at checkout counter.
two sisters reunite after…
two sisters reunite after
two sisters reunite after—
two sisters reunite after eigh
two sisters reunite after e…
上一篇: 2.python中self详解
下一篇: 加强外链建设,对百度排名效果立竿见影
推荐阅读
-
解析smarty 截取字符串函数 truncate的用法介绍
-
JavaScript常用截取字符串的三种方式用法区别实例解析
-
解析smarty 截取字符串函数 truncate的用法介绍_PHP
-
MySQL字符串截取函数用法介绍
-
Python:在python中将字符串内所有非空格字符加 1(ASCII码)|| 介绍ord()函数的用法
-
mysql截取的字符串函数substring_index的用法_MySQL
-
解析smarty 截取字符串函数 truncate的用法介绍_PHP教程
-
解析smarty 截取字符串函数 truncate的用法介绍_PHP
-
Mysql字符串截取函数SUBSTRING的用法说明_MySQL
-
Mysql字符串截取函数SUBSTRING的用法说明