开发者

How to show a fixed number of characters from a sentence - symfony

开发者 https://www.devze.com 2023-03-31 17:38 出处:网络
I have a sentece that works like a title, but is to 开发者_StackOverflowbig to be shown in the page. I can I set the variable to only show a bit of the sentence in symfony?

I have a sentece that works like a title, but is to 开发者_StackOverflowbig to be shown in the page. I can I set the variable to only show a bit of the sentence in symfony? Thanks.


Use the TextHelper. (use_helper('Text');) It has some nice functions like truncate_text().

You can use it like this (in your View):

<?php use_helper('Text'); ?>
...
<?php echo truncate_text($text, 50); ?>

(The optional third parameter specifies which text you want to add when the text is being truncated (defaults to '...'). The optional boolean fourth parameter specifies wether you want to break on spaces explicitly. (and not somewhere in the middle of a word).

0

精彩评论

暂无评论...
验证码 换一张
取 消