php smarty php函数,smarty中使用php函数的方法

本节内容:

如何在smarty中使用php函数?

例子:

复制代码 代码示例:

/**

* smarty模板引擎中使用php函数

* by www.jbxue.com

*/

require 'libs/Smarty.class.php';

$smarty=new Smarty;

$smarty->compile_check=true;

$smarty->debugging=true;

$str1='testtesttesttest';

$str2='this is a';

$str3='脚本 学堂 www.jbxue.com';

$str4='this is four';

$smarty->assign('str1',$str1);

$smarty->assign('str2',$str2);

$smarty->assign('str3',$str3);

$smarty->assign('str4',$str4);

$smarty->display('testtest.tpl');

?>

{$str1|strlen}

{$str2|strpos:'is'}

{'utf-8'|iconv:'gb2312':$str3}

{$str4|str_pad:20:"-=":STR_PAD_LEFT}

输出结果:

16

2

测试:

-=-=-=-=this is four

说明:

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

在编程时,用到了这个:

复制代码 代码示例:

{$name|str_ireplace:"$name":$arr

顺带分享下,有兴趣的朋友可以琢磨下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值