Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file modifier.adjust.php

Documentation is available at modifier.adjust.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * Smarty plugin
  10.  * -------------------------------------------------------------
  11.  * Type:     modifier
  12.  * Name:     adjust
  13.  * Purpose:  Adjust a string to a certain length if necessary,
  14.  *           optionally splitting in the middle of a word, and
  15.  *           appending the $etc string or padding the string
  16.  *             using $pad as filler.
  17.  * -------------------------------------------------------------
  18.  */
  19. function smarty_modifier_adjust($string$length 80
  20.                                   $pad '&nbsp;'
  21.                                   $etc '...',
  22.                                   $break_words false)
  23. {
  24.     if ($length == 0)
  25.         return '';
  26.  
  27.     if (strlen($string$length{
  28.         $length -= strlen($etc);
  29.         $fragment substr($string0$length+1);
  30.         if ($break_words)
  31.             $fragment substr($fragment0-1);
  32.         else
  33.             $fragment preg_replace('/\s+(\S+)?$/'''$fragment);
  34.         return $fragment.$etc;
  35.     elseif(strlen($string)<$length{
  36.         return $string.str_repeat($pad,$length-strlen($string));
  37.     else {
  38.         return $string;
  39.     }
  40.      
  41. }
  42.  
  43. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:08 +0000 by phpDocumentor 1.5.0-lsces