Kill lui lei Dog---Smarty no:06 design Chapter 4 Variable adjuster

Source: Internet
Author: User

{$var |regex_replace: "/[\t\n]/": ""}: Regular replacement

{$var |replace: "AA": "BB"}: Character substitution

{$var |spacify: "^^"}: intervening spaces (between characters and characters intervening spaces)

{$var |string_format: '%d '}: String formatted%d: Formatted As Integer%s: formatted string

{$var |strip: "*"}: Remove extra spaces

{$var |strip_tags}: Removing HTML tags

{$var |truncate:30: "..."}: Intercept characters of a specified length (English)

{$var |wordwrap:30: "<br>"}: Row width constraint

demo3.php

<?PHPrequire"Smarty/smarty.class.php ";$smarty=NewSmarty ();$str="Hello World";$str 2="Nihao123″;$STR 3= "<ul><li>hello ul li</li></ul>";$smarty-Assign (' str ',$str);$smartyAssign (' str2′,$str 2);$smartyAssign (' str3′,$STR 3);$smartyDisplay ("demo3.html");

Demo3.html

<!DOCTYPE HTML><HTML><Head><MetaCharSet= ' utf-8′><title></title></Head><Body>Regular substitution: {$str 2|regex_replace: "/\d\d\d/": "* * *"}<HR/>normal substitution: {$str 2|replace: ' 123′: ' php '}<HR/>character intervening spaces: {$str |spacify: ' * '}<HR/>Format data: {$str |string_format: '%s '}<HR/>Remove extra spaces: {$str |strip: ' * '}<!– Use the * number in place of the space –><HR/>strip_tags Remove HTML tag: {$str 3|strip_tags}<HR/>string interception: {$str |truncate:10}<HR/>row width constraint: {$str |wordwrap:10: '<HR>'}</Body></HTML>

Variable adjusters can also be combined to apply

Basic syntax:

{$var |capitalize|truncate:30: "..." |replace: "AA": "BB"}

A: First capitalize the first letter of the Var variable, intercept the 30-character length, and use ... Instead, replace the substring AA for BB

Kill lui lei Dog---Smarty no:06 design Chapter 4 Variable adjuster

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.