Exemplo n.º 1
0
 /**
  * 汉字拼音
  *
  * @param string $str
  * @param string $charset     输入编码 'utf-8' or 'gb2312' or 'big5'
  * @return string
  */
 public static function PinYin($str, $charset = 'utf-8')
 {
     if ($charset != 'gb2312') {
         $str = self::convert($str, $charset, 'gb2312');
     }
     self::$table = (include TABLE_DIR . '/pinyin.php');
     $gblen = strlen($str);
     $pin = '';
     for ($i = 0; $i < $gblen; $i++) {
         $c = ord($str[$i]);
         if ($c > 0xa0) {
             $index = 0x10000 - ($c * 0x100 + ord($str[++$i]));
             $pin .= self::getPinYin($index);
         } else {
             $pin .= $str[$i];
         }
     }
     return trim($pin);
 }
Exemplo n.º 2
0
 /**   
 * js 中的unescape功能   
 *    
 * @param string $str       源字符串   
 * @param string $charset   目标字符串编码 'utf-8' or 'gb2312' or 'big5'   
 * @return string   
 */
 public static function unescape($str, $charset = 'utf-8')
 {
     $charset = strtolower($charset);
     self::$target_lang = str_replace(array('gbk', 'utf8', 'big-5'), array('gb2312', 'utf-8', 'big5'), $charset);
     if (self::$target_lang != 'utf-8' && !(USEEXISTS && (function_exists('mb_convert_encoding') || function_exists('iconv')))) {
         self::$table = array_flip(self::loadtable('unescapeto' . $charset));
     }
     return preg_replace_callback('/[\\\\|%]u(\\w{4})/iU', array('Charset', 'descape'), $str);
 }