[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/template/smarty/plugins/ -> modifier.utf8_wordwrap.php (source)

   1  <?php
   2  /**

   3   * Smarty plugin

   4   * @package    Smarty

   5   * @subpackage plugins

   6   */
   7  
   8  
   9  /**

  10   * Smarty wordwrap modifier    plugin

  11   *

  12   * Type:     modifier<br>

  13   * Name:     wordwrap<br>

  14   * Purpose:     wrap a    string of text at a    given length

  15   * @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php

  16   *            wordwrap (Smarty online    manual)

  17   * @author     Monte Ohrt    <monte at ohrt dot com>

  18   * @param string

  19   * @param integer

  20   * @param string

  21   * @param boolean

  22   * @return string

  23   */
  24  function smarty_modifier_utf8_wordwrap($string,$length=80,$break="\n",$cut=false)
  25  {
  26      return utf8_wordwrap($string, $length, $break, $cut);
  27  }
  28  
  29  /** 

  30   * wordwrap for utf8 encoded strings, http://milianw.de/section:Snippets/content:UTF-8-Wordwrap

  31   * 

  32   * @param string $str 

  33   * @param integer $len 

  34   * @param string $what 

  35   * @return string 

  36   */ 
  37   
  38  function utf8_wordwrap($str, $width, $break,$cut = false){ 
  39      if(!$cut){ 
  40          $regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.',}\b#U'; 
  41      } else { 
  42          $regexp = '#^(?:[\x00-\xFF]|[\xC0-\xFF][\x80-\xBF]+){'.$width.'}#'; 

  43      } 
  44      if(function_exists('mb_strlen')){ 
  45          $str_len = mb_strlen($str,'UTF-8'); 
  46      } else { 
  47          $str_len = preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $str, $var_empty); 
  48      } 
  49      $while_what = ceil($str_len / $width); 
  50      $i = 1; 
  51      $return = ''; 
  52      while ($i < $while_what){ 
  53          preg_match($regexp, $str,$matches); 
  54          $string = $matches[0]; 
  55          $return .= $string . $break; 
  56          $str = substr($str,strlen($string)); 
  57          $i++; 
  58      } 
  59      return $return.$str; 
  60  }
  61  
  62  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics