modifier.summary.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
13 /**
14  * Truncate a text while preserving words, removing line breaks, tags and
15  * decoding html entities.
16  *
17  * Example:
18  * @code
19  * <meta name="description" content="{$text|summary}">
20  * @endcode
21  *
22  * @param $text The text to truncate
23  * @param $length The number of chars to truncate to (default: 150)
24  * @param $suffix The suffix to append (default: …)
25  * @return String
26  */
27 function smarty_modifier_summary($text, $length=150, $suffix='…') {
28  $text = trim(preg_replace("/ +/", " ", preg_replace("/[\r\n\t]/", " ", html_entity_decode(strip_tags($text)))));
29  return StringUtil::cropString($text, $length, $suffix);
30 }
31 ?>
StringUtil provides support for string manipulation.
Definition: StringUtil.php:18