20 variable operators commonly used in the phpsmarty template engine and 20 variable operators frequently used by smarty * syntax: {variable name | operator :}
* Capitalize --- uppercase letters
* Count_characters --- calculates the number of characters
* Cat --- connection string
* Count_paragraphs --- calculate the number of paragraphs
* Count_sentences --- calculate the number of periods
* Count_words --- calculate the number of words
* Date_format --- time format
* Default --- default
* Escape --- transcoding
* Indent --- indent
* Lower --- lower case
* Nl2br --- Replace the linefeed
* Regex_replace --- regular expression replacement
* Replace --- replace
* Spacify --- enter
* String_format --- string formatting
* Strip --- remove unnecessary spaces
* Strip_tags --- remove html tags
* Truncate --- truncate
* Upper --- uppercase
* Wordwrap -- constrain the row width
Usage:
Index. php
The code is as follows:
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
Raw data: {$ title}
After using the capitalize variable operator: {$ title | capitalize}
After the count_characters variable operator is used: {$ title | count_characters}
After using the cat variable operator: {$ title | cat: "wwww.baidu.com "}
After using the count_paragraphs variable operator: {$ title | count_paragraphs}
After using the count_sentences variable function operator: {$ title | count_sentences}
After using the count_words variable function: {$ title | count_words}
Original time data: {$ d}
Use the date_format variable function operation: {$ d | date_format: "% Y-% m-% d "}
Call time with smarty. now: {$ smarty. now | date_format: "% Y-% m-% d "}
Use the default variable function operation: {$ title1 | default: "No such variable "}
Use the escape variable function operation: {$ title | escape: "html "}
Use the indent variable function operation: {$ title | indent: 2 :""}
Use the lower variable function operation: {$ title | lower}
Using the upper variable function: {$ title | upper}
Use the replace variable function operation: {$ title | replace: "is ":"@@"}
Use the spacify variable function: {$ title | spacify :"_"}
Use the string_format variable function operation: {$ nubmer | string_format: "%. 2f "}
Using the strip variable function: {$ title | strip :"_"}
Use the strip_tags variable function operation: {$ title | strip_tags}
Use the truncate variable function operation: {$ title | truncate: 30 :"..."}
Use the wordwrap variable function operation: {$ title | wordwrap: 10 :"
"}