Source for file modifier.wordwrap_i18n.php

Documentation is available at modifier.wordwrap_i18n.php

  1. <?php
  2. /**
  3.  *  smarty modifier:文字列のwordwrap処理
  4.  *
  5.  *  sample:
  6.  *  <code>
  7.  *  {"あいうaえaおaかきaaaくけこ"|wordwrap_i18n:8}
  8.  *  </code>
  9.  *  <code>
  10.  *  あいうa
  11.  *  えaおaか
  12.  *  きaaaく
  13.  *  けこ
  14.  *  </code>
  15.  *
  16.  *  @param  string  $string wordwrapする文字列
  17.  *  @param  string  $break  改行文字
  18.  *  @param  int     $width  wordwrap幅(半角$width文字でwordwrapする)
  19.  *  @param  int     $indent インデント幅(半角$indent文字)
  20.  *                           数値を指定するが、はじめの行はインデントされない
  21.  *  @return string  wordwrap処理された文字列
  22.  */
  23. function smarty_modifier_wordwrap_i18n($string$width$break "\n"$indent 0)
  24. {
  25.     $ctl Ethna_Controller::getInstance();
  26.     $client_enc $ctl->getClientEncoding();
  27.  
  28.     //    いわゆる半角を単位にしてwrapする位置を測るため、いったん
  29.     //    EUC_JP に変換する
  30.     $euc_string mb_convert_encoding($string'EUC_JP'$client_enc);
  31.  
  32.     $r "";
  33.     $i "$breakstr_repeat(" "$indent);
  34.     $tmp $euc_string;
  35.     do {
  36.         $n strpos($tmp$break);
  37.         if ($n !== false && $n $width{
  38.             $s substr($tmp0$n);
  39.             $r .= $s $i;
  40.             $tmp substr($tmpstrlen($sstrlen($break));
  41.             continue;
  42.         }
  43.  
  44.         $s mb_strimwidth($tmp0$width""'EUC_JP');
  45.         $tmp substr($tmpstrlen($s));
  46.         $r .= $s ((strlen($tmp0)?$i:'');
  47.     while (strlen($tmp0);
  48.  
  49.     //    最後に、クライアントエンコーディングに変換
  50.     $r mb_convert_encoding($r$client_enc'EUC_JP');
  51.  
  52.     return $r;
  53. }

Documentation generated on Fri, 11 Nov 2011 03:58:45 +0900 by phpDocumentor 1.4.3