Example 5-21. truncateindex.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... 

解决方案 »

  1.   

    唠叨老大请指教:
    .tpl file content:
    {/$test|truncate:50:"..."/}$tpl->assign('test','常常 的想,现在的你,就在我身边露出笑脸。我这张旧船票是否能够登上你的破船?');
    OUTPUT:
    常常...$tpl->assign('test','常常 的想,现在 的你,就在我身边露出笑脸。我这张旧船票是否能够登上你的破船?');
    OUTPUT:
    常常 的想,现在...$tpl->assign('test','常常 的想,现在 的你,就在我 身边露出笑脸。我这张旧船票是否能够登上你的破船?');
    OUTPUT:
    常常 的想,现在 的你,就在我...难道是我SMARTY版本不对或文件出问题?
      

  2.   

    是有中文的问题。中文是连续的,smarty作为一个单词对待
      

  3.   

    嗯,你加ture参数的时候会不会造成把一个汉字分割开的情况?
     估计要自己处理了,或者改smarty的程序
      

  4.   

    呵呵,,打扰各位了,,是由于我写代码时偷懒,少加了TRUE参数,,呵呵,以前代码写太多了,看来只能改SMARTY程序了
    谢谢大家