开发者

How to show a fixed number of characters from a sentence - 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜