【问题标题】:How to get the sub-string starting from specified position till the string ends in smarty?如何获取从指定位置开始的子字符串,直到字符串以 smarty 结尾?
【发布时间】:2014-10-18 09:07:25
【问题描述】:

我想在大文本上实现引导程序的折叠功能。但不幸的是,它没有按预期工作。以下是我尝试过的代码:

  {foreach from=$quant_vol_data item=data key=key}    
    <div class="row">
    <div class="col-xs-12">
      <label for="name" class="col-lg-2">Details :</label>          
      <div class="col-lg-8">
        {$data.details|substr:0:100}
      </div>
      <div id="comment_{$data.id}" class="collapse out">
        {$data.details|substr:101:''} {* here I'm getting error since the end position is not mentioned *}
      </div>  
        {if $data.details|@count_characters > 101}
          <a data-toggle="collapse" data-target="#comment_{$data.id}">Readmore...</a>
        {/if}
    </div>
  </div>
  {/foreach}

我想获取从位置 101 到字符串结尾的字符串的一部分。但我无法用上面的代码得到它。有人可以帮我吗?

提前致谢。

【问题讨论】:

    标签: twitter-bootstrap twitter-bootstrap-3 smarty substr smarty2


    【解决方案1】:

    你只需要省略第二个数字,所以你应该使用:

    {$data.details|substr:101}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      相关资源
      最近更新 更多