[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/include/smarty_plugins/ -> modifier.mb_truncate.php (source)

   1  <?php
   2  /**
   3   * Smarty plugin
   4   * @package Smarty
   5   * @subpackage plugins
   6   */
   7  
   8  
   9  /**
  10   * Smarty mb_truncate modifier plugin
  11   *
  12   * Type:     modifier<br>
  13   * Name:     mb_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. (MultiByte version)
  17   * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
  18   *          truncate (Smarty online manual)
  19   * @param string
  20   * @param string
  21   * @param integer
  22   * @param string
  23   * @param boolean
  24   * @return string
  25   */
  26  function smarty_modifier_mb_truncate($string, $length = 80, $etc = '...', $break_words = false)
  27  {
  28      if ($length == 0)
  29      {
  30          return '';
  31      }
  32      $string = str_replace("&amp;", "&", $string);
  33      if(function_exists("mb_internal_encoding")
  34          && function_exists("mb_strlen")
  35          && function_exists("mb_substr")
  36          )
  37      {
  38          mb_internal_encoding("UTF8");
  39          
  40          if (mb_strlen($string) > $length) 
  41          {
  42              $length -= mb_strlen($etc);
  43              
  44              if (!$break_words)
  45              {
  46                  $string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length+1));
  47              }
  48              $string =  mb_substr($string, 0, $length).$etc;
  49          }
  50      }
  51      else
  52      {
  53          //modifier.truncate
  54          if (strlen($string) > $length) 
  55          {
  56              $length -= strlen($etc);
  57              if (!$break_words)
  58              {
  59                  $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
  60              }
  61              
  62              $string =  substr($string, 0, $length).$etc;
  63          } 
  64      }
  65      
  66      $string = str_replace("&", "&amp;", $string);
  67      return $string;
  68  }
  69  
  70  /* vim: set expandtab: */
  71  
  72  ?> 


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics