php中获取smarty中变量,php中smarty模版引擎中变量操作符汇总及使用方法详解

smarty模板引擎中常用的20个变量操作符如下:

语法:{变量名|操作符:}

capitalize ---首字母大写

count_characters ---计算字符数

cat ---连接字符串

count_paragraphs ---计算段落数

count_sentences ---计算句数

count_words ---计算词数

date_format ---时间格式

default ---默认

escape ---转码

indent ---缩进

lower ---小写

nl2br ---换行符替换为

regex_replace ---正则替换

replace ---替换

spacify ---插空

string_format ---字符串格式化

strip ---去除多余空格

strip_tags ---去除html标签

truncate ---截取

upper ---大写

wordwrap --约束行宽

在php中的使用方法:

index.php

include("smarty_inc.php");

$name = "My name is MaJi,age 22,sex boy.aaaaaa.";

$smarty->assign("title", $name);

$smarty->assign("row", $row);

$smarty->assign("d",strtotime("-0"));

$smarty->assign("nubmer", 342345.736524);

$smarty->display("index.html");

?>

在模板中的使用方法:

index.html

原始数据:{$title}

使用capitalize变量操作符后:{$title|capitalize}

使用count_characters变量操作符后:{$title|count_characters}

使用cat变量操作符后:{$title|cat:"wwww.baidu.com"}

使用count_paragraphs变量操作符后:{$title|count_paragraphs}

使用count_sentences变量函数操作符后:{$title|count_sentences}

使用count_words变量函数操作后:{$title|count_words}

原始时间数据:{$d}

使用date_format变量函数操作:{$d|date_format:"%Y-%m-%d"}

使用smarty.now调用时间:{$smarty.now|date_format:"%Y-%m-%d"}

使用default变量函数操作:{$title1|default:"没有这个变量"}

使用escape变量函数操作:{$title|escape:"html"}

使用indent变量函数操作:{$title|indent:2:" "}

使用lower变量函数操作: {$title|lower}

使用upper变量函数操作:{$title|upper}

使用replace变量函数操作:{$title|replace:"is":"@@"}

使用spacify变量函数操作:{$title|spacify:"_"}

使用string_format变量函数操作:{$nubmer|string_format:"%.2f"}

使用strip变量函数操作:{$title|strip:"_"}

使用strip_tags变量函数操作:{$title|strip_tags}

使用truncate变量函数操作:{$title|truncate:30:"..."}

使用wordwrap变量函数操作:{$title|wordwrap:10:"
"}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值