SMARTY中截取字串的问题

死胖子 2005-05-05 01:39:15
{$xx|truncate:400:"..."}
如上,当$xx中存在空格时如:"abc cdefg省略N个"
显示时就会有问题,有时候只显示"abc...",如果将400改的更大一些,或小一些或作些微调又会正常,请问各位是否遇到过同样的问题,怎么解决,或者有其它更好的方法,不需要用到truncate?
请指导。
...全文
127 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
pmaster 2005-05-06
  • 打赏
  • 举报
回复
http://www.womai.cn/
pmaster 2005-05-06
  • 打赏
  • 举报
回复
28729799
死胖子 2005-05-06
  • 打赏
  • 举报
回复
呵呵,,打扰各位了,,是由于我写代码时偷懒,少加了TRUE参数,,呵呵,以前代码写太多了,看来只能改SMARTY程序了。。。
谢谢大家
helloyou0 2005-05-05
  • 打赏
  • 举报
回复
嗯,你加ture参数的时候会不会造成把一个汉字分割开的情况?
估计要自己处理了,或者改smarty的程序
死胖子 2005-05-05
  • 打赏
  • 举报
回复
有解否?
helloyou0 2005-05-05
  • 打赏
  • 举报
回复
是有中文的问题。中文是连续的,smarty作为一个单词对待
死胖子 2005-05-05
  • 打赏
  • 举报
回复
我是2.6.3的
死胖子 2005-05-05
  • 打赏
  • 举报
回复
唠叨老大请指教:
.tpl file content:
{/$test|truncate:50:"..."/}

$tpl->assign('test','常常 的想,现在的你,就在我身边露出笑脸。我这张旧船票是否能够登上你的破船?');
OUTPUT:
常常...

$tpl->assign('test','常常 的想,现在 的你,就在我身边露出笑脸。我这张旧船票是否能够登上你的破船?');
OUTPUT:
常常 的想,现在...

$tpl->assign('test','常常 的想,现在 的你,就在我 身边露出笑脸。我这张旧船票是否能够登上你的破船?');
OUTPUT:
常常 的想,现在 的你,就在我...

难道是我SMARTY版本不对或文件出问题?
skystar008 2005-05-05
  • 打赏
  • 举报
回复
学习了。
xuzuning 2005-05-05
  • 打赏
  • 举报
回复
Example 5-21. truncate

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}

OUTPUT:

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...


21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧