An introduction to the usage of parsing smarty intercepting string function truncate _php tips

Source: Internet
Author: User
Smarty Truncate intercept string
Intercepts a length of characters from the beginning of a string, with a default length of 80
Specifies the second parameter as the length of the Intercept string
By default, Smarty is intercepted to the end of a word,
If you need to be precise to how many characters to intercept you can use the third argument to set it to "true"
The specific usage is as follows:
Copy Code code as follows:

index.php $smarty = new Smarty;
$smarty->assign (' ArticleTitle ', ' two sisters reunite after eighteen Years at Checkout Counter. ');
$smarty->display (' Index.tpl ');
Index.tpl
{$articleTitle}
{$articleTitle |truncate}
{$articleTitle |truncate:30}
{$articleTitle |truncate:30: ""}
{$articleTitle |truncate:30: "---"}
{$articleTitle |truncate:30: "": true}
{$articleTitle |truncate:30: "...": true}

Output Results:
Two sisters reunite after eighteen Years at Checkout Counter.
Two sisters reunite after eighteen Years at Checkout Counter.
Two sisters reunite ...
Two sisters reunite after
Two sisters reunite after-
Two sisters reunite after Eigh
Two sisters reunite after E ...

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.