Smarty变量操作符学习

来源:互联网 发布:怎么用网络挣钱 编辑:程序博客网 时间:2024/06/07 08:15

<?phpheader("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:如果有换行就加1Count_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} * 9Date_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!linkthis 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 isPHPvideos,think you! */$val="this is PHP videos, think you!";$smarty->assign("text", $val);$smarty->assign("date", strtotime("-0"));$smarty->display("test2.html");?>





0 0