Source for file modifier.truncate_i18n.php

Documentation is available at modifier.truncate_i18n.php

  1. <?php
  2. /**
  3.  *  smarty modifier:文字列切り詰め処理(i18n対応)
  4.  *
  5.  *  sample:
  6.  *  <code>
  7.  *  {"日本語です"|truncate_i18n:7:"..."}
  8.  *  </code>
  9.  *  <code>
  10.  *  日本...
  11.  *  </code>
  12.  *
  13.  *  @param  int     $len        最大文字幅
  14.  *  @param  string  $postfix    末尾に付加する文字列
  15.  */
  16. function smarty_modifier_truncate_i18n($string$len 80$postfix "...")
  17. {
  18.     $ctl Ethna_Controller::getInstance();
  19.     $client_enc $ctl->getClientEncoding();
  20.  
  21.     //    いわゆる半角を単位にしてwrapする位置を測るため、いったん
  22.     //    EUC_JP に変換する
  23.     $euc_string mb_convert_encoding($string'EUC_JP'$client_enc);
  24.  
  25.     $r mb_strimwidth($euc_string0$len$postfix'EUC_JP');
  26.  
  27.     //    最後に、クライアントエンコーディングに変換
  28.     $r mb_convert_encoding($r$client_enc'EUC_JP');
  29.  
  30.     return $r;
  31. }

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