Smarty变量操作符学习

<?php
header("Content-Type:text/html;charset:gbk");
require_once '../include/Smarty_inc.php';
/*
认识Smarty的变量操作符

Capitalize[首字母大写]
//主要是针对英文字符串
 * This Is PHP Videos, Think You! :如果PHP100时他就认为这不是一个单词而不转换
Count_characters[计算字符数]
//计算变量字符长度
 * 25:不包括空格,包括标点符号
Cat[连接字符串]
//类似于php中点(.)的作用,可以用于补充一部分内容或者随机数,为了防止别人采集
 * {$text|cat:" last cat string"}
 * this is PHP videos, think you! last cat string 
Count_paragraphs[计算段落数]
//很少用到,一般计算新闻段落时会用到
 * {$text|count_paragraphs}
 * 1:如果有换行就加1
Count_sentences[计算句数]
//计算有多少句话
 * this is PHP videos, a. b. c.  think you!
 * {$text|count_sentences}
 * 4:按. ! ? 计数,,(逗号是不算一句完整的话的)
Count_words[计算词数]
//很好理解
 * this is PHP videos, a. b. c.  think you!
 * {$text|count_words}
 * 9
Date_format[时间格式]
//显示时间格式
 * $smarty->assign("date", strtotime("-0"));
 * 原始内容 : {$date}<br />
{$date|date_format:"%Y-%m-%d"}
<!-- 显示当前时间 --><br />
{$smarty.now|date_format:"%Y-%m-%d"}
Default[默认]
//默认显示什么值
 * {$text_NotExists|default:"没有定义该变量"}
Escape[转码]  html, htmlall, url
//转html代码,也可以将内容转换成十六进制的
 * $val="this is PHP videos,  think you!<a href=\"#\">link</a>";
 * {$text}<br />
{$text|escape:html}
{$text|escape:url}
this is PHP videos, think you!link
this is PHP videos, think you!<a href="#">link</a> 
this%20is%20PHP%20videos%2C%20%20think%20you%21%3Ca%20href%3D%22%23%22%3Elink%3C%2Fa%3E 
Indent[缩进]
//针对于排版的,最好用这个缩进,便于移植
 * {$text}<br />
{$text|indent:10:" "}
this is PHP videos, think you!link
           this is PHP videos, think you!link 
Lower[小写]
//将英文字母全部变成小写
 * {$text|lower}
 * this is php videos, think you!link 
Nl2br[换行符替换成<br />]
//将换行符替换成html的换行<br />
 * this is PHP videos, \n think you!
 * {$text}<br />
 * {$text|nl2br}
this is PHP videos, think you!
 this is PHP videos, 
 think you! 
Regex_replace[正则替换]
//正则替换
 * 
Replace[替换]
//替换
 *  {$text}<br />
{$text|replace:"is":"haha"}
 * this is PHP videos, think you!
 thhaha haha PHP videos, think you! 
Spacify[插空]
//就是在某某之间插进去内容,默认插入空格,可以用来防止注入什么的
 * {$text|spacify}
t h i s i s P H P v i d e o s , t h i n k y o u ! 
String_format[字符串格式化]
//字符格式化   %.2f  %d
 * {$text|string_format:"%.2f"}
123456.12 
Strip[去除(多余空格)]
//去除空格,可以去除中间的空格,就是所有的空格,也可以将空格替换成其他的
 * {$text|strip:""} //{$text|strip:"="} 
thisisPHPvideos,thinkyou!   this=is=PHP=videos,=think=you! 
Strip_tags[去除html标签]
//去掉html中的标签
Truncate[截取]
//可以用来控制长度,多余的用...来表示
 * {$text|truncate:14:"..."}
 this is PHP videos, think you!
this is PHP... 
Upper[大写]
//将英文字符转换为大写
 * {$text|upper}
 * THIS IS PHP VIDEOS, THINK YOU!LINK 
Wordwrap[行宽约束]
//一行显示多少条,够了多少换行
 * 第一个参数设置最大长度,第二个参数设置操作
 * 这里例子就是达到10个字符就添加换行
 * {$text|wordwrap:10:"<br />"}
  this is PHP videos, think you!
 this is
PHP
videos,
think you! 

*/


$val="this is PHP videos, think you!";
$smarty->assign("text", $val);
$smarty->assign("date", strtotime("-0"));
$smarty->display("test2.html");

?>







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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值