smarty模板引擎的变量修饰器

这个名称听起来邮电怪,简单的说就是smarty对字符串的操作,例如大小写转换、日期格式化、正则替换等。smarty上手不是很困难下面我整理了一些smarty的字符串操作的例子

left_delimiter="<{";
$smart->right_delimiter="}>";
//字符串连接
$smart->assign("str","hello");
//取得字符串长度
$smart->assign("str2","我是中国人");
//把字符串里的中文变为小写(如果要变为大写则使用upper)
$smart->assign("str3","MY NAME IS AMY");
//正则替换
$smart->assign("str4","我喜欢昆明5");
//字符串替换
$smart->assign("str5","我喜欢杭州");
$smart->display("strtest.tpl");
?>

下面是模板文件

<{$str|cat:' world' }>
字符串的长度是:<{$str2|count_characters}>
<{*日期格式化*}> <{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}>
<{$str3|lower:' world' }>
<{$str4|regex_replace:"/[\\d]/":""}>
<{$str5|replace:"杭州":"上海"}>
除这些外其实还有好些个方法,大家查阅文档看看

你可能感兴趣的:(smarty,变量修饰器,smarty,模板引擎,变量修饰器)