PHP smarty template engine variable operators and how to use _php tutorial

Source: Internet
Author: User
Tags smarty template
Smarty Common 20 variable operators * Use syntax: {variable name | operator:}
* Capitalize---initial capital letter
* Count_characters---Count of characters
* Cat---connection string
* Count_paragraphs---Calculation of the number of paragraphs
* Count_sentences---Calculation of sentences
* Count_words---Calculation of the number of words
* Date_format---time format
* Default---Defaults
* Escape---transcoding
* Indent---Indent
* Lower---lowercase
* NL2BR---newline character replaced by
* Regex_replace---regular replacement
* Replace---Replacement
* Spacify---intervening spaces
* String_format---string formatting
* Strip---remove extra spaces
* Strip_tags---Remove HTML tags
* Truncate---interception
* Upper---capital
* WordWrap--Constrain line width

How to use:
index.php
Copy CodeThe 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 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}
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: {$title 1|default: "Without this variable"}
Operation with escape variable function: {$title |escape: "HTML"}
Use the Indent variable function operation: {$title |indent:2: ""}
Use the lower variable function operation: {$title |lower}
Use the upper variable function operation: {$title |upper}
Use the Replace variable function operation: {$title |replace: "is": "@@"}
Use the spacify variable function operation: {$title |spacify: "_"}
Use the String_format variable function operation: {$nubmer |string_format: "%.2f"}
Use the Strip variable function operation: {$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: "
"}

http://www.bkjia.com/PHPjc/320939.html www.bkjia.com true http://www.bkjia.com/PHPjc/320939.html techarticle smarty commonly used 20 variable operators * Use syntax: {variable name | operator:} * Capitalize---Initial capital letter * Count_characters---count characters * Cat---connection string * Coun ...

  • Related Article

    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.