douqian1517 2011-06-09 19:42
浏览 35
已采纳

Smarty获取文件扩展名

is there a way in Smarty to get the file extension of a string. I have been searching for the explode equivalent although can't seem to find anything.

I am wanting to display a different icon based on the type of file eg. doc,docx,pdf

  • 写回答

2条回答 默认 最新

  • douwen5924 2011-06-09 20:02
    关注

    Since you can use php functions as modifiers, you can use the function pathinfo()

    All php-functions can be used as modifiers implicitly, as demonstrated in the example above. However, using php-functions as modifiers has two little pitfalls:

    First - sometimes the order of the function-parameters is not the desirable one. Formatting $foo with {"%2.f"|sprintf:$foo} actually works, but asks for the more intuitive, like {$foo|string_format:"%2.f"} that is provided by the Smarty distribution.

    Secondly - if security is enabled, all php-functions that are to be used as modifiers have to be declared trusted in the $modifiers property of the securty policy. See the Security section for details. Source

    <?php
    
    $smarty->assign('filename', 'foo\bar.txt');
    
    ?>
    
    {* template *}
    
    {$filename|pathinfo:$smarty.const.PATHINFO_EXTENSION}
    {* outputs 'txt' *}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题