• smarty变量调节器


    1、capitalize[首字符大写]  调用方法:

    <?php$smarty->assign('articleTitle', 'next x-men film, x3, delayed.');?>  
    调用方法:
    {$articleTitle}
    {$articleTitle|capitalize}
    {$articleTitle|capitalize:true}   
    实现结果:
    next x-men film, x3, delayed.
    Next X-Men Film, x3, Delayed.
    Next X-Men Film, X3, Delayed.

    2、cat[连接字符串]

    <?php$smarty->assign('articleTitle', "Psychics predict world didn't end");?>
    
    调用方法:
    
    {$articleTitle|cat:" yesterday."}
    
    实现结果:
    
    Psychics predict world didn't end yesterday.

    3、date_format[格式化日期]

    <?php
    $config['date'] = '%I:%M %p';
    $config['time'] = '%H:%M:%S';
    $smarty->assign('config', $config);
    $smarty->assign('yesterday', strtotime('-1 day'));
    ?>
    
    这个模板使用 $smarty.now 提取当前时间:
    {$smarty.now|date_format}
    {$smarty.now|date_format:"%D"}
    {$smarty.now|date_format:$config.date}
    {$yesterday|date_format}
    {$yesterday|date_format:"%A, %B %e, %Y"}
    {$yesterday|date_format:$config.time}
    
    运行结果:
    
    Jan 1, 2022
    01/01/22
    02:33 pm
    Dec 31, 2021
    Monday, December 1, 2021
    14:33:00

    4、regex_replace[ 正则替换]

    <?php
    $smarty->assign("zhengze","hae2525ahwo3w");
    
    将字符串中的数字换为QQ:
    <div><{$zhengze|regex_replace:"/d/":"QQ"}></div>
    
    运行结果:
    haeQQQQQQQQahwoQQw

    5、replace[替换]

    <?php
    $smarty->assign("tihuan","nice to meet you");
    
    将字母e替换为#
    <div><{$tihuan}></div>
    <div><{$tihuan|replace:"e":"#"}></div>
    
    运行结果:
    nice to meet you
    nic# to m##t you

    6、truncate[截取]

    <?php
    $smarty->assign("jiequ","welcome to zibo");
    
    截取10个字符,句尾或句中显示2个*
    <div><{$jiequ}></div>
    <div><{$jiequ|truncate:1}></div>
    <div><{$jiequ|truncate:10:"**"}></div>
    <div><{$jiequ|truncate:10:"**":true}></div>
    <div><{$jiequ|truncate:10:"**":true:true}></div>
    运行结果:
    welcome to zibo
    ...
    welcome**
    welcome **
    welc**zibo
  • 相关阅读:
    SQL入门语句之SELECT和WHERE
    SQL入门语句之INSERT、UPDATE和DELETE
    SQL入门语句之CREATE
    iOS高效调试
    兼容iOS 10 资料整理笔记
    iOS中常见的一些宏
    Extjs 日期的处理;字符串转日期;分隔获得小时;天数差;小时差;
    Ext.MessageBox.show更改按钮中的名称
    Extjs日期/可编辑表格grid/显示不正确————解决方案
    ExtJs Grid行显示不同颜色2
  • 原文地址:https://www.cnblogs.com/m-m-g-y0416/p/5701739.html
Copyright © 2020-2023  润新知