PHP smarty template engine variable operator and use method _php templates

Source: Internet
Author: User
Tags string format smarty template
Smarty commonly used 20 variable operators * Use syntax: {variable name | operator:}
* Capitalize---First letter capital
* Count_characters---count characters
* Cat---connection string
* Count_paragraphs---Calculation of paragraphs
* Count_sentences---Calculation of the number of sentences
* Count_words---Number of words calculated
* Date_format---time format
* Default---Defaults
* Escape---transcoding
* Indent---Indent
* Lower---lowercase
* NL2BR---newline character replaced by
* Regex_replace---Replacement
* Replace---Replacement
* Spacify---interpolation
* String_format---string format
* Strip---remove extra space
* Strip_tags---Remove HTML tags
* Truncate---interception
* Upper---Caps
* WordWrap--Constraint line width

How to use:
index.php
Copy Code code 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 operation: {$title |count_words}
Raw time data: {$d}
Using 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 action: {$title 1|default: "No This Variable"}
Operation with escape variable function: {$title |escape: "HTML"}
Using the Indent variable function operation: {$title |indent:2:}
Using the lower variable function operation: {$title |lower}
Using the upper variable function operation: {$title |upper}
Use the Replace variable function action: {$title |replace: "is": "@@"}
Using the spacify variable function operation: {$title |spacify: "_"}
Using the String_format variable function operation: {$nubmer |string_format: "%.2f"}
Use the Strip variable function action: {$title |strip: "_"}
Using the Strip_tags variable function operation: {$title |strip_tags}
Use TRUNCATE variable function action: {$title |truncate:30: "..."}
Using the WordWrap variable function operation: {$title |wordwrap:10: "<br>"}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.