Calculates the number of words and calculates the number of words in the variable.
$str = <Index.html
<{$str |count_words}>
The result is: 12
7, Date_format
Date format, specific parameters, here are only examples of Chinese-style date format
index.php
$tpl->assign (' Date ', Time ()); Pass time stamp
Index.html
<{$date |date_format: '%y-%m-%d%h:%m:%s '}>
The result is: 2012-01-26 14:37:22
8. Default
By default, a default value is set for an empty variable, and when the variable is empty or unassigned, the output is replaced by the given default value.
index.php
$TPL->assign (' str ', '); Assign a value to null
Index.html
<{$str |default: ' Default output ... '}>, <{$string |default: ' No definition, default output ... '}>
The result is: Default output ..., no definition, default output ...
9. Escape
transcoding, for HTML transcoding, URL transcoding, converting single quotes, hex transcoding, hex beautification, or JavaScript transcoding on non-transcoding variables, HTML transcoding by default
index.php
$html = <
< for="" (var="" i="0;"><100; i++)="" {="" window.alert(i);="" }js;$tpl-="">
assign (' HTML ', $html);//html$tpl->assign (' url ', ' http:// Www.google.com.hk '); Url$tpl->assign (' JS ', $JS); JavaScript
Index.html
HTML transcoding: <{$html |escape: "html"}>url transcoding: <{$url |escape: "URL"}>js transcoding: <{$js |escape: "JavaScript"}>
The result is:
HTML transcoding: Googleurl transcoding: Http%3a%2f%2fwww.google.com.hkjs transcoding:
10, indent
Indents, each line indents the string, the first parameter specifies how many strings are indented, the default is four characters, and the second argument, which specifies what characters the indentation uses instead.
11, lower
lowercase, the variable string is lowercase.
How to use: <{$str |lower}>
12, Upper
Uppercase, change the variable to uppercase.
How to use: <{$str |upper}>
13, NL2BR
Replace line breaks with
All line breaks will be replaced with the PHP nl2br () function.
14, Regex_replace
Regular substitution, finding and replacing regular expressions, is the same as the syntax of Preg_replace ().
index.php
$TPL->assign (' str ', ' http://www.google.com ');
Index.html
<{$str |regex_replace: '/go{2}gle/': ' Baidu '}>
The result is: http://www.baidu.com
15. Replace
Replace, simple search and replace string.
16, Spacify
Intervening spaces, intervening spaces (do not know what this word means, as the name implies ^ ^) is a string between each character insert a space or other characters (strings).
index.php
$TPL->assign (' str ', ' Hello World!!! ');
Index.html
<{$str |spacify: "^^"}>
The result: h^^e^^l^^l^ ^o^ ^ ^^ w^ ^o^ ^r^^l^^d^^! ^^! ^^!
17, String_format
String formatting, which is a method for formatting floating-point numbers, such as decimal numbers. Format using sprintf syntax.
index.php
$TPL->assign (' num ', 23.5787446);
Index.html
<{$num |string_format: "%.2f"}><{$num |string_format: "%d"}>
The results are: 23.58, 23
18, strip
Replace all repeating spaces, line breaks, tab to individual
index.php
$TPL->assign (' str ', "grandmother Of\neight makes\t hole in one.");
Index.html
<{$str |strip: ""}>
The result is: Grandmother of eight makes hole in one.
Source:
Grandmother of eight makes hole in one.
19, Strip_tags
Remove
<和>
all labels between, including
<和>
.
index.php
$TPL->assign (' str ', ' Google ');
Index.html
<{$str |strip_tags}>
The result: Google (source code is also Google, removed tags and tags)
20, truncate
Intercept, intercept the beginning of a string. The default is 80, you can specify the second parameter as the string after the truncation of what character, by default, Smarty will intercept the end of a word, if you want to accurately intercept how many characters, the third parameter to "true".
index.php
Copy the code as follows: $tpl->assign (' str ', ' there once was a mountain, there was a temple on the hill. There is an old monk and a little monk in the Temple ... ');
Index.html
<{$str |truncate:10: ' ... ':true}>
The result: There used to be a mountain, a mountain ...
More about PHP related content readers can view the topic: "Smarty Template Primer Basic Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " PHP Basic Grammar Introductory tutorial, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL database Operations Primer and PHP Common database operations Tips Summary
It is hoped that this article will be helpful to everyone based on smarty template PHP program design.
Articles you may be interested in: