Common 20 variable operators in smarty * use 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
Copy codeThe Code is as follows:
Include ("smarty_inc.php ");
$ Name = "My name is MaJi, age 22, sex boy. <a href => aaaaaa </a> .";
$ 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: "<br> "}