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

Source for file Common.php

Documentation is available at Common.php

  1. <?php
  2. /**
  3.  * For PHP internal iconv/mbstring support on KSC5601 package
  4.  *
  5.  * Check iconv or mbstring support, and auto select iconv or mbstring api.
  6.  * If support both iconv and mbstring extensions, first iconv.
  7.  *
  8.  * @category   Charset
  9.  * @package    KSC5601
  10.  * @subpackage KSC5601_Common
  11.  * @author     JoungKyun.Kim <http://oops.org>
  12.  * @copyright  (c) 2015, JoungKyun.Kim
  13.  * @license    BSD License
  14.  * @version    $Id$
  15.  * @link       http://pear.oops.org/package/KSC5601
  16.  * @filesource
  17.  */
  18.  
  19. /**
  20.  * For PHP internal iconv/mbstring support
  21.  * 
  22.  * This class support check of using iconv/mbstring method and iconv/mbstring
  23.  * wrapper method.
  24.  *
  25.  * @package KSC5601
  26.  */
  27. {
  28.     // {{{ public (bool) is_iconv ()
  29.     /**
  30.      * Check to enable iconv extension on this session.
  31.      *
  32.      * @access public
  33.      * @return boolean 
  34.      * @param void 
  35.      * @see extension_loaded
  36.      */
  37.     function is_iconv ({
  38.         return extension_loaded ('iconv');
  39.     }
  40.     // }}}
  41.  
  42.     // {{{ public (bool) is_mbstring ()
  43.     /**
  44.      * Check to enable mbstring extension on this session.
  45.      *
  46.      * @access public
  47.      * @return boolean 
  48.      * @param void 
  49.      * @see extension_loaded
  50.      */
  51.     function is_mbstring ({
  52.         return extension_loaded ('mbstring');
  53.     }
  54.     // }}}
  55.  
  56.     // {{{ public (bool) is_extfunc ()
  57.     /**
  58.      * Check to enable iconv or mbstring extension on this session.
  59.      *
  60.      * @access public
  61.      * @return boolean If support to iconv or mbstring, return true
  62.      * @param void 
  63.      */
  64.     function is_extfunc ({
  65.         if $this->is_iconv (=== true || $this->is_mbstring (=== true )
  66.             return true;
  67.         return false;
  68.     }
  69.     // }}}
  70.  
  71.     // {{{ public (string|false) extfunc ($from, $to, $str)
  72.     /**
  73.      * iconv/mbstring wrapper function
  74.      *
  75.      * If enable iconv, use iconv. If disable iconv and enable mbstring,
  76.      * use mbstring. If disable both iconv and mbstring, return false
  77.      * @access public
  78.      * @return false|stringReturn false when don't support both iconv and mbstring
  79.      * @param string $from  From charset
  80.      * @param string $to    To charset
  81.      * @param string $str   Given strings.
  82.      */
  83.     function extfunc ($from$to$str{
  84.         if self::is_iconv (=== true )
  85.             return iconv ($from$to$str);
  86.  
  87.         if self::is_mbstring (=== true )
  88.             return mb_convert_encoding ($str$to$from);
  89.  
  90.         return false;
  91.     }
  92.     // }}}
  93. }
  94.  
  95. /*
  96.  * Local variables:
  97.  * tab-width: 4
  98.  * c-basic-offset: 4
  99.  * End:
  100.  * vim600: noet sw=4 ts=4 fdm=marker
  101.  * vim<600: noet sw=4 ts=4
  102.  */
  103. ?>

Documentation generated on Tue, 14 May 2019 01:59:40 +0900 by phpDocumentor 1.4.4