zoukankan      html  css  js  c++  java
  • (转)smarty里使用php函数

    1. <?php   
    2. require 'libs/Smarty.class.php';   
    3.     $smarty=new Smarty;   
    4.     $smarty->compile_check=true;   
    5.     $smarty->debugging=true;   
    6.     $str1='testtesttesttest';   
    7.     $str2='this is a';   
    8.     $str3='鐢ㄦ潵娴嬭瘯';   
    9.     $str4='this is four';   
    10.     $smarty->assign('str1',$str1);   
    11.     $smarty->assign('str2',$str2);   
    12.     $smarty->assign('str3',$str3);   
    13.     $smarty->assign('str4',$str4);   
    14.     $smarty->display('testtest.tpl');   
    15. ?>     
    16. <html>
      <head>
      </head>
      <body>
      <p>{$str1|strlen}</p>
      <p>{$str2|strpos:'is'}</p>
      <p>{'utf-8'|iconv:'gb2312':$str3}</p>
      <p>{$str4|str_pad:20:"-=":STR_PAD_LEFT}</p>
      </body>
      </html>
    17. 输出结果为:

      16

      2

      用来测试

      -=-=-=-=this is four

      我用四个变量,分别处理1,2,3,4个不能的参数,特此记录一下,模板中调用变量时,当只有一个参数是,就直接{$str1|函数名},当有函数有两个参数时,{第一个参数|函数名:第二个参数},当有三个参数时,{第一个参数|函数名:第二个参数:第三个参数},,当有4,5,,,参数时,以此类推,,,,,,,,,,,,

      今天在描红个的时候,用到了这个{$name|str_ireplace:"<span style='color:#03C200;font-size:14px'>$name</span>":$arr

  • 相关阅读:
    网络负载均衡LVS
    JS 模仿红绿灯(控制台)
    【转】wrk 压力测试的 lua脚本
    linux开机 自动挂载和启动jar包
    【转】jprofiler linux配置需要监听的程序的端口
    时间复杂度总结
    Windows Subsystem for Linux (WSL) 安装
    敬畏用户
    Golang语言HTTP客户端实践
    Groovy入门常用语法
  • 原文地址:https://www.cnblogs.com/showker/p/1978309.html
Copyright © 2011-2022 走看看