Smarty now shows the various ways of Word count _php tutorials

Source: Internet
Author: User
Is there a function to limit the number of words to display?

Yes! With truncate

Intercepts a length of characters from the beginning of a string. The default is 80.

You can also specify the second argument as the text string appended to the Intercept string. The append string is computed in the intercept length.

By default, Smarty is truncated to the end of a word.

If you want to accurately intercept the number of characters, change the third parameter to "true"

CODE:

index.php:

$smarty =new Smarty;

$smarty->assign (' ArticleTitle ', ' both sisters reunite after eighteen years at Checkoutcounter. ');

$smarty->display (' Index.tpl ');

Www.2cto.com

INDEX.TPL:

{$articleTitle}

{$articleTitle |truncate}

{$articleTitle |truncate:30}

{$articleTitle |truncate:30: ""}

{$articleTitle |truncate:30: "---"}

{$articleTitle |truncate:30: "": true}

{$articleTitle |truncate:30: "...": true}

OUTPUT:

Sisters reunite after eighteen years at Checkout Counter.

Sisters reunite after eighteen years at Checkout Counter.

Sisters reunite after ...

Sisters reunite after

Sisters reunite after---

Sisters reunite after Eigh

Sisters reunite after E ...

http://www.bkjia.com/PHPjc/478558.html www.bkjia.com true http://www.bkjia.com/PHPjc/478558.html techarticle are there any features that limit the number of words to display? Use truncate to intercept a certain length of character from the beginning of a string. The default is 80. You can also specify a second parameter as the append in the Intercept string ...

  • 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.