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. phpCopyCodeThe 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 using the count_characters variable OPERATOR: {$ 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}
raw time data: {$ d}
use the date_format Variable Function operation: {$ d | date_format: "% Y-% m-% d"}
Use smarty. now call time: {$ smarty. now | date_format: "% Y-% m-% d"}
use the default Variable Function operation: {$ title1 | default: "No such variable"}
function operation with escape variable: {$ title | escape: "html"}
function operation with indent variable: {$ title | indent: 2: ""}
use lower Variable Function operation: {$ title | Lower}
use upper Variable Function operation: {$ title | Upper}
replace Variable Function operation: {$ title | Replace: "is": ""}
Use spacify Variable Function operation: {$ title | spacify: "_"}
Use string_format Variable Function operation: {$ nubmer | string_format: "%. 2f "}
Use strip Variable Function operation: {$ title | Strip:" _ "}
Use strip_tags Variable Function operation: {$ title | strip_tags}
use the truncate Variable Function operation: {$ title | truncate: 30 :"... "}
function operation using the wordwrap variable: {$ title | wordwrap: 10:"
"}