/[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.1 - (show annotations)
Wed Oct 9 00:53:36 2002 UTC (21 years, 10 months ago) by cvsjoko
Branch: MAIN
no message

1 <?php
2
3 /*
4 * Smarty plugin
5 * -------------------------------------------------------------
6 * Type: modifier
7 * Name: truncate
8 * Purpose: Truncate a string to a certain length if necessary,
9 * optionally splitting in the middle of a word, and
10 * appending the $etc string.
11 * -------------------------------------------------------------
12 */
13 function smarty_modifier_truncate($string, $length = 80, $etc = '...',
14 $break_words = false)
15 {
16 if ($length == 0)
17 return '';
18
19 if (strlen($string) > $length) {
20 $length -= strlen($etc);
21 $fragment = substr($string, 0, $length+1);
22 if ($break_words)
23 $fragment = substr($fragment, 0, -1);
24 else
25 $fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
26 return $fragment.$etc;
27 } else
28 return $string;
29 }
30
31 /* vim: set expandtab: */
32
33 ?>

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