/[cvs]/nfo/php/libs/net.php.smarty/plugins/modifier.truncate.php
ViewVC logotype

Contents of /nfo/php/libs/net.php.smarty/plugins/modifier.truncate.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Wed Jun 16 21:58:17 2004 UTC (20 years ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +23 -13 lines
updated to smarty-2.6.3

1 <?php
2 /**
3 * Smarty plugin
4 * @package Smarty
5 * @subpackage plugins
6 */
7
8
9 /**
10 * Smarty truncate modifier plugin
11 *
12 * Type: modifier<br>
13 * Name: truncate<br>
14 * Purpose: Truncate a string to a certain length if necessary,
15 * optionally splitting in the middle of a word, and
16 * appending the $etc string.
17 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
18 * truncate (Smarty online manual)
19 * @param string
20 * @param integer
21 * @param string
22 * @param boolean
23 * @return string
24 */
25 function smarty_modifier_truncate($string, $length = 80, $etc = '...',
26 $break_words = false)
27 {
28 if ($length == 0)
29 return '';
30
31 if (strlen($string) > $length) {
32 $length -= strlen($etc);
33 if (!$break_words)
34 $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
35
36 return substr($string, 0, $length).$etc;
37 } else
38 return $string;
39 }
40
41 /* vim: set expandtab: */
42
43 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed