解析smarty 截取字符串函数 truncate的用法介绍

 2025-01-15  阅读 432  评论 8  点赞 204

摘要:smarty truncate 截取字符串从字符串开始处截取某长度的字符,默认的长度为80指定第二个参数作为截取字符串的长度默认情况下,smarty会截取到一个词的末尾,如果需要精确到截取多少个字符可以使用第三个参数,将其设为”true”具体用法如下:复制代码 代码如下://index.php $
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…


标签:phpphp教程

评论列表:

  •   xiaoming22
     发布于 1月前回复该评论
  • 又学到了新知识!
显示更多评论

发表评论:

管理员

承接各种程序开发,外贸网站代运营,外贸网站建设等项目
  • 内容2462
  • 积分67666
  • 金币89666

Copyright © 2024 LS'Blog-保定PHP程序员老宋个人博客 Inc. 保留所有权利。 Powered by LS'blog 3.0.3

页面耗时0.0285秒, 内存占用1.94 MB, 访问数据库30次

冀ICP备19034377号