欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

TP函数库function

程序员文章站 2022-03-03 20:41:55
...

function yd_friend_date(sTime,type = ‘normal’) {

if (!$sTime) return '';

//sTime=源时间,cTime=当前时间,dTime=时间差

$cTime        =    time();

$dTime        =    $cTime - $sTime;

if( $dTime < 0 ){

    return "".date("Y-m-d H:i",$sTime)."";

}

$dDay        =    intval(date("z",$cTime)) - intval(date("z",$sTime));

//$dDay        =    intval($dTime/3600/24);

$dYear        =    intval(date("Y",$cTime)) - intval(date("Y",$sTime));

//normal:n秒前,n分钟前,n小时前,日期

if($type=='normal'){

    if( $dTime == 0 ){

        return "刚刚";

    }elseif( $dTime < 60 ){

        return "".$dTime.'秒前';

    }elseif( $dTime < 3600 ){

        return "".intval($dTime/60).'分钟前';

        //今天的数据.年份相同.日期相同.

    }elseif( $dYear==0 && $dDay == 0  ){

        //return intval($dTime/3600)."小时前";

        return "今天".date('H:i',$sTime).'';

    }elseif($dYear==0){

        return "".date("m月d日 H:i",$sTime).'';

    }else{

        return "".date("Y-m-d H:i",$sTime).'';

    }

}elseif($type=='*'){

    if( $dTime < 60 ){

        return $dTime."秒前";

    }elseif( $dTime < 3600 ){

        return intval($dTime/60)."分钟前";

    }elseif( $dTime >= 3600 && $dDay == 0  ){

        return intval($dTime/3600)."小时前";

    }elseif( $dDay > 0 && $dDay<=7 ){

        return intval($dDay)."天前";

    }elseif( $dDay > 7 &&  $dDay <= 30 ){

        return intval($dDay/7) . '周前';

    }elseif( $dDay > 30 ){

        return intval($dDay/30) . '个月前';

    }

//full: Y-m-d , H:i:s

}elseif($type=='full'){

    return date("Y-m-d , H:i:s",$sTime);

}elseif($type=='ymd'){

    return date("Y-m-d",$sTime);

}else{

    if( $dTime < 60 ){

        return $dTime."秒前";

    }elseif( $dTime < 3600 ){

        return intval($dTime/60)."分钟前";

    }elseif( $dTime >= 3600 && $dDay == 0  ){

        return intval($dTime/3600)."小时前";

    }elseif($dYear==0){

        return date("Y-m-d H:i:s",$sTime);

    }else{

        return date("Y-m-d H:i:s",$sTime);

    }

}

}

function yd_mime_type($ext){

static $mime_types = array (

        'apk'     => 'application/vnd.android.package-archive',

        '3gp'     => 'video/3gpp',

        'ai'      => 'application/postscript',

        'aif'     => 'audio/x-aiff',

        'aifc'    => 'audio/x-aiff',

        'aiff'    => 'audio/x-aiff',

        'asc'     => 'text/plain',

        'atom'    => 'application/atom+xml',

        'au'      => 'audio/basic',

        'avi'     => 'video/x-msvideo',

        'bcpio'   => 'application/x-bcpio',

        'bin'     => 'application/octet-stream',

        'bmp'     => 'image/bmp',

        'cdf'     => 'application/x-netcdf',

        'cgm'     => 'image/cgm',

        'class'   => 'application/octet-stream',

        'cpio'    => 'application/x-cpio',

        'cpt'     => 'application/mac-compactpro',

        'csh'     => 'application/x-csh',

        'css'     => 'text/css',

        'dcr'     => 'application/x-director',

        'dif'     => 'video/x-dv',

        'dir'     => 'application/x-director',

        'djv'     => 'image/vnd.djvu',

        'djvu'    => 'image/vnd.djvu',

        'dll'     => 'application/octet-stream',

        'dmg'     => 'application/octet-stream',

        'dms'     => 'application/octet-stream',

        'doc'     => 'application/msword',

        'dtd'     => 'application/xml-dtd',

        'dv'      => 'video/x-dv',

        'dvi'     => 'application/x-dvi',

        'dxr'     => 'application/x-director',

        'eps'     => 'application/postscript',

        'etx'     => 'text/x-setext',

        'exe'     => 'application/octet-stream',

        'ez'      => 'application/andrew-inset',

        'flv'     => 'video/x-flv',

        'gif'     => 'image/gif',

        'gram'    => 'application/srgs',

        'grxml'   => 'application/srgs+xml',

        'gtar'    => 'application/x-gtar',

        'gz'      => 'application/x-gzip',

        'hdf'     => 'application/x-hdf',

        'hqx'     => 'application/mac-binhex40',

        'htm'     => 'text/html',

        'html'    => 'text/html',

        'ice'     => 'x-conference/x-cooltalk',

        'ico'     => 'image/x-icon',

        'ics'     => 'text/calendar',

        'ief'     => 'image/ief',

        'ifb'     => 'text/calendar',

        'iges'    => 'model/iges',

        'igs'     => 'model/iges',

        'jnlp'    => 'application/x-java-jnlp-file',

        'jp2'     => 'image/jp2',

        'jpe'     => 'image/jpeg',

        'jpeg'    => 'image/jpeg',

        'jpg'     => 'image/jpeg',

        'js'      => 'application/x-javascript',

        'kar'     => 'audio/midi',

        'latex'   => 'application/x-latex',

        'lha'     => 'application/octet-stream',

        'lzh'     => 'application/octet-stream',

        'm3u'     => 'audio/x-mpegurl',

        'm4a'     => 'audio/mp4a-latm',

        'm4p'     => 'audio/mp4a-latm',

        'm4u'     => 'video/vnd.mpegurl',

        'm4v'     => 'video/x-m4v',

        'mac'     => 'image/x-macpaint',

        'man'     => 'application/x-troff-man',

        'mathml'  => 'application/mathml+xml',

        'me'      => 'application/x-troff-me',

        'mesh'    => 'model/mesh',

        'mid'     => 'audio/midi',

        'midi'    => 'audio/midi',

        'mif'     => 'application/vnd.mif',

        'mov'     => 'video/quicktime',

        'movie'   => 'video/x-sgi-movie',

        'mp2'     => '',

        'mp3'     => '',

        'mp4'     => 'video/mp4',

        'mpe'     => 'video/mpeg',

        'mpeg'    => 'video/mpeg',

        'mpg'     => 'video/mpeg',

        'mpga'    => '',

        'ms'      => 'application/x-troff-ms',

        'msh'     => 'model/mesh',

        'mxu'     => 'video/vnd.mpegurl',

        'nc'      => 'application/x-netcdf',

        'oda'     => 'application/oda',

        'ogg'     => 'application/ogg',

        'ogv'     => 'video/ogv',

        'pbm'     => 'image/x-portable-bitmap',

        'pct'     => 'image/pict',

        'pdb'     => 'chemical/x-pdb',

        'pdf'     => 'application/pdf',

        'pgm'     => 'image/x-portable-graymap',

        'pgn'     => 'application/x-chess-pgn',

        'pic'     => 'image/pict',

        'pict'    => 'image/pict',

        'png'     => 'image/png',

        'pnm'     => 'image/x-portable-anymap',

        'pnt'     => 'image/x-macpaint',

        'pntg'    => 'image/x-macpaint',

        'ppm'     => 'image/x-portable-pixmap',

        'ppt'     => 'application/vnd.ms-powerpoint',

        'ps'      => 'application/postscript',

        'qt'      => 'video/quicktime',

        'qti'     => 'image/x-quicktime',

        'qtif'    => 'image/x-quicktime',

        'ra'      => 'audio/x-pn-realaudio',

        'ram'     => 'audio/x-pn-realaudio',

        'ras'     => 'image/x-cmu-raster',

        'rdf'     => 'application/rdf+xml',

        'rgb'     => 'image/x-rgb',

        'rm'      => 'application/vnd.rn-realmedia',

        'roff'    => 'application/x-troff',

        'rtf'     => 'text/rtf',

        'rtx'     => 'text/richtext',

        'sgm'     => 'text/sgml',

        'sgml'    => 'text/sgml',

        'sh'      => 'application/x-sh',

        'shar'    => 'application/x-shar',

        'silo'    => 'model/mesh',

        'sit'     => 'application/x-stuffit',

        'skd'     => 'application/x-koan',

        'skm'     => 'application/x-koan',

        'skp'     => 'application/x-koan',

        'skt'     => 'application/x-koan',

        'smi'     => 'application/smil',

        'smil'    => 'application/smil',

        'snd'     => 'audio/basic',

        'so'      => 'application/octet-stream',

        'spl'     => 'application/x-futuresplash',

        'src'     => 'application/x-wais-source',

        'sv4cpio' => 'application/x-sv4cpio',

        'sv4crc'  => 'application/x-sv4crc',

        'svg'     => 'image/svg+xml',

        'swf'     => 'application/x-shockwave-flash',

        't'       => 'application/x-troff',

        'tar'     => 'application/x-tar',

        'tcl'     => 'application/x-tcl',

        'tex'     => 'application/x-tex',

        'texi'    => 'application/x-texinfo',

        'texinfo' => 'application/x-texinfo',

        'tif'     => 'image/tiff',

        'tiff'    => 'image/tiff',

        'tr'      => 'application/x-troff',

        'tsv'     => 'text/tab-separated-values',

        'txt'     => 'text/plain',

        'ustar'   => 'application/x-ustar',

        'vcd'     => 'application/x-cdlink',

        'vrml'    => 'model/vrml',

        'vxml'    => 'application/voicexml+xml',

        'wav'     => 'audio/x-wav',

        'wbmp'    => 'image/vnd.wap.wbmp',

        'wbxml'   => 'application/vnd.wap.wbxml',

        'webm'    => 'video/webm',

        'wml'     => 'text/vnd.wap.wml',

        'wmlc'    => 'application/vnd.wap.wmlc',

        'wmls'    => 'text/vnd.wap.wmlscript',

        'wmlsc'   => 'application/vnd.wap.wmlscriptc',

        'wmv'     => 'video/x-ms-wmv',

        'wrl'     => 'model/vrml',

        'xbm'     => 'image/x-xbitmap',

        'xht'     => 'application/xhtml+xml',

        'xhtml'   => 'application/xhtml+xml',

        'xls'     => 'application/vnd.ms-excel',

        'xml'     => 'application/xml',

        'xpm'     => 'image/x-xpixmap',

        'xsl'     => 'application/xml',

        'xslt'    => 'application/xslt+xml',

        'xul'     => 'application/vnd.mozilla.xul+xml',

        'xwd'     => 'image/x-xwindowdump',

        'xyz'     => 'chemical/x-xyz',

        'zip'     => 'application/zip'

);

return isset($mime_types[$ext]) ? $mime_types[$ext] : 'application/octet-stream';

}

function yd_color_text($str){

$len        = mb_strlen($str);

$colorTxt   = '';

for($i=0; $i<$len; $i++) {

    $colorTxt .=  ''.mb_substr($str,$i,1,'utf-8').'';

}

return $colorTxt;

}

function yd_rand_color(){

return '#'.sprintf("X",mt_rand(0,255)).sprintf("X",mt_rand(0,255)).sprintf("X",mt_rand(0,255));

}

function yd_to_date(time,format = ‘Y-m-d H:i:s’) {

if (empty ( $time )) {

    return '';

}

$format = str_replace ( '#', ':', $format );

return date ($format, $time );

}

function yd_file_ext($file) {

//return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));

return pathinfo($file, PATHINFO_EXTENSION);

}

function yd_dir_path($path) {

$path = str_replace('\\', '/', $path);

if(substr($path, -1) != '/') $path = $path.'/';

return $path;

}

function yd_dir_list(path,exts = ”, $list= array()) {

$path = yd_dir_path($path);

$files = glob($path.'*');

foreach($files as $v) {

    $fileext = yd_file_ext($v);

    if (!$exts || preg_match("/\.($exts)/i", $v)) {

        $list[] = $v;

        if (is_dir($v)) {

            $list = yd_dir_list($v, $exts, $list);

        }

    }

}

return $list;

}

function yd_key_links(txt,links, $replacenum = -1) {

if ($links) {

    $pattern = $replace = array();

    foreach ($links as $v) {

        //wordpress关键链接插件:$regEx = '\'(?!((<.*?)|(<>]*?)>)|([^>]*?))\'s' . $case;

        //$pattern[] = '/(?!(]*?<\/a>))/s';

        //会替换回车

        //$pattern[] = '/(?!((<.*?)|(<>]*?)>)|([^>]*?<\/a>))/s'; 

        $pattern[] = '/(?!((<.*?)|(<>]*?)>)|([^>]*?<\/a>)|([^>]*?<\/script>))/s';



        //$pattern[] = '/(?!(<\/a>)/s';  //原始

        //$replace[] = '' . $v[0] . '';

        $replace[] = "{$v[0]}";

    }

    $txt = preg_replace($pattern, $replace, $txt, $replacenum);

}

return $txt;

}

function yd_auto_link($str){

$str = eregi_replace('(((f|ht){1}tp://)[[email protected]:%_\+.~#?&//=]+)', '\1', $str);

if( stripos($str, "http") === FALSE ){

    $str = eregi_replace('(www.[[email protected]:%_\+.~#?&//=]+)', '\1', $str);

}else{

    $str = eregi_replace('([[:space:]()[{}])(www.[[email protected]:%_\+.~#?&//=]+)', '\1\2', $str);

}

return $str;

}

function yd_qq_face(qq,style = 41, $tip = ”){

$qqText = "\"$tip\"

填写图片摘要(选填)
“;

return $qqText;

}

function yd_taobao_face(number,tip = ”){

    $str = "

    $tip

    ";

    return $str;

}

function yd_ali_face(number,tip = ”){

$str = "

           $tip

           ";

return $str;

}

function yd_interali_face(number,tip = ”){

$str = "

$str .= "  style='text-align:center;' data-uid='{$number}'>";

$str .= "

$str .= " src='http://amos.alicdn.com/online.aw?v=2&uid={$number}&site=enaliint&s=22&charset=UTF-8'>";

$str .= "{$number}";

return $str;

}

function yd_msn_face(number,tip = ”){

$msn = __ROOT__."/Public/Images/online/msn.gif";

$str = "

$tip

";

return $str;

}

function yd_skype_face(number,tip = ”){

$str = "

$tip

";

return $str;

}

function yd_ip2location(ip,type=0){

static $_loc = array();

$k = md5($ip);

if( isset($_loc[$k]) ){

    return $_loc[$k];

}

switch($type){

    case 1:  //使用本地库

        break;

    case 0:  //使用新浪接口(默认)

    default: 

        $api = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=$ip";

        $content = file_get_contents($api);

        $data = json_decode($content, true);

        if( !isset($data['ret'] ) || $data['ret'] < 0 ) return false;

        $area = array(

                'Country'=>$data['country'],

                'Province'=>$data['province'],

                'City'=>$data['city'],

                'District'=>$data['district'],

                'ISP'=>$data['isp'],

                'Type'=>$data['type'],

                'Description'=>$data['desc']

        );

}

$_loc[$k] = $area;

return $area;

}

//拼音获取函数===========================================================

function yd_pinyin(str,first =true, $code=’UTF8’){

$_Data = array ( 'zuo' => '-10254', 'zun' => '-10256', 'zui' => '-10260', 'zuan' => '-10262', 'zu' => '-10270', 'zou' => '-10274', 'zong' => '-10281', 'zi' => '-10296', 'zhuo' => '-10307', 'zhun' => '-10309', 'zhui' => '-10315', 'zhuang' => '-10322', 'zhuan' => '-10328', 'zhuai' => '-10329', 'zhua' => '-10331', 'zhu' => '-10519', 'zhou' => '-10533', 'zhong' => '-10544', 'zhi' => '-10587', 'zheng' => '-10764', 'zhen' => '-10780', 'zhe' => '-10790', 'zhao' => '-10800', 'zhang' => '-10815', 'zhan' => '-10832', 'zhai' => '-10838', 'zha' => '-11014', 'zeng' => '-11018', 'zen' => '-11019', 'zei' => '-11020', 'ze' => '-11024', 'zao' => '-11038', 'zang' => '-11041', 'zan' => '-11045', 'zai' => '-11052', 'za' => '-11055', 'yun' => '-11067', 'yue' => '-11077', 'yuan' => '-11097', 'yu' => '-11303', 'you' => '-11324', 'yong' => '-11339', 'yo' => '-11340', 'ying' => '-11358', 'yin' => '-11536', 'yi' => '-11589', 'ye' => '-11604', 'yao' => '-11781', 'yang' => '-11798', 'yan' => '-11831', 'ya' => '-11847', 'xun' => '-11861', 'xue' => '-11867', 'xuan' => '-12039', 'xu' => '-12058', 'xiu' => '-12067', 'xiong' => '-12074', 'xing' => '-12089', 'xin' => '-12099', 'xie' => '-12120', 'xiao' => '-12300', 'xiang' => '-12320', 'xian' => '-12346', 'xia' => '-12359', 'xi' => '-12556', 'wu' => '-12585', 'wo' => '-12594', 'weng' => '-12597', 'wen' => '-12607', 'wei' => '-12802', 'wang' => '-12812', 'wan' => '-12829', 'wai' => '-12831', 'wa' => '-12838', 'tuo' => '-12849', 'tun' => '-12852', 'tui' => '-12858', 'tuan' => '-12860', 'tu' => '-12871', 'tou' => '-12875', 'tong' => '-12888', 'ting' => '-13060', 'tie' => '-13063', 'tiao' => '-13068', 'tian' => '-13076', 'ti' => '-13091', 'teng' => '-13095', 'te' => '-13096', 'tao' => '-13107', 'tang' => '-13120', 'tan' => '-13138', 'tai' => '-13147', 'ta' => '-13318', 'suo' => '-13326', 'sun' => '-13329', 'sui' => '-13340', 'suan' => '-13343', 'su' => '-13356', 'sou' => '-13359', 'song' => '-13367', 'si' => '-13383', 'shuo' => '-13387', 'shun' => '-13391', 'shui' => '-13395', 'shuang' => '-13398', 'shuan' => '-13400', 'shuai' => '-13404', 'shua' => '-13406', 'shu' => '-13601', 'shou' => '-13611', 'shi' => '-13658', 'sheng' => '-13831', 'shen' => '-13847', 'she' => '-13859', 'shao' => '-13870', 'shang' => '-13878', 'shan' => '-13894', 'shai' => '-13896', 'sha' => '-13905', 'seng' => '-13906', 'sen' => '-13907', 'se' => '-13910', 'sao' => '-13914', 'sang' => '-13917', 'san' => '-14083', 'sai' => '-14087', 'sa' => '-14090', 'ruo' => '-14092', 'run' => '-14094', 'rui' => '-14097', 'ruan' => '-14099', 'ru' => '-14109', 'rou' => '-14112', 'rong' => '-14122', 'ri' => '-14123', 'reng' => '-14125', 'ren' => '-14135', 're' => '-14137', 'rao' => '-14140', 'rang' => '-14145', 'ran' => '-14149', 'qun' => '-14151', 'que' => '-14159', 'quan' => '-14170', 'qu' => '-14345', 'qiu' => '-14353', 'qiong' => '-14355', 'qing' => '-14368', 'qin' => '-14379', 'qie' => '-14384', 'qiao' => '-14399', 'qiang' => '-14407', 'qian' => '-14429', 'qia' => '-14594', 'qi' => '-14630', 'pu' => '-14645', 'po' => '-14654', 'ping' => '-14663', 'pin' => '-14668', 'pie' => '-14670', 'piao' => '-14674', 'pian' => '-14678', 'pi' => '-14857', 'peng' => '-14871', 'pen' => '-14873', 'pei' => '-14882', 'pao' => '-14889', 'pang' => '-14894', 'pan' => '-14902', 'pai' => '-14908', 'pa' => '-14914', 'ou' => '-14921', 'o' => '-14922', 'nuo' => '-14926', 'nue' => '-14928', 'nuan' => '-14929', 'nv' => '-14930', 'nu' => '-14933', 'nong' => '-14937', 'niu' => '-14941', 'ning' => '-15109', 'nin' => '-15110', 'nie' => '-15117', 'niao' => '-15119', 'niang' => '-15121', 'nian' => '-15128', 'ni' => '-15139', 'neng' => '-15140', 'nen' => '-15141', 'nei' => '-15143', 'ne' => '-15144', 'nao' => '-15149', 'nang' => '-15150', 'nan' => '-15153', 'nai' => '-15158', 'na' => '-15165', 'mu' => '-15180', 'mou' => '-15183', 'mo' => '-15362', 'miu' => '-15363', 'ming' => '-15369', 'min' => '-15375', 'mie' => '-15377', 'miao' => '-15385', 'mian' => '-15394', 'mi' => '-15408', 'meng' => '-15416', 'men' => '-15419', 'mei' => '-15435', 'me' => '-15436', 'mao' => '-15448', 'mang' => '-15454', 'man' => '-15625', 'mai' => '-15631', 'ma' => '-15640', 'luo' => '-15652', 'lun' => '-15659', 'lue' => '-15661', 'luan' => '-15667', 'lv' => '-15681', 'lu' => '-15701', 'lou' => '-15707', 'long' => '-15878', 'liu' => '-15889', 'ling' => '-15903', 'lin' => '-15915', 'lie' => '-15920', 'liao' => '-15933', 'liang' => '-15944', 'lian' => '-15958', 'lia' => '-15959', 'li' => '-16155', 'leng' => '-16158', 'lei' => '-16169', 'le' => '-16171', 'lao' => '-16180', 'lang' => '-16187', 'lan' => '-16202', 'lai' => '-16205', 'la' => '-16212', 'kuo' => '-16216', 'kun' => '-16220', 'kui' => '-16393', 'kuang' => '-16401', 'kuan' => '-16403', 'kuai' => '-16407', 'kua' => '-16412', 'ku' => '-16419', 'kou' => '-16423', 'kong' => '-16427', 'keng' => '-16429', 'ken' => '-16433', 'ke' => '-16448', 'kao' => '-16452', 'kang' => '-16459', 'kan' => '-16465', 'kai' => '-16470', 'ka' => '-16474', 'jun' => '-16647', 'jue' => '-16657', 'juan' => '-16664', 'ju' => '-16689', 'jiu' => '-16706', 'jiong' => '-16708', 'jing' => '-16733', 'jin' => '-16915', 'jie' => '-16942', 'jiao' => '-16970', 'jiang' => '-16983', 'jian' => '-17185', 'jia' => '-17202', 'ji' => '-17417', 'huo' => '-17427', 'hun' => '-17433', 'hui' => '-17454', 'huang' => '-17468', 'huan' => '-17482', 'huai' => '-17487', 'hua' => '-17496', 'hu' => '-17676', 'hou' => '-17683', 'hong' => '-17692', 'heng' => '-17697', 'hen' => '-17701', 'hei' => '-17703', 'he' => '-17721', 'hao' => '-17730', 'hang' => '-17733', 'han' => '-17752', 'hai' => '-17759', 'ha' => '-17922', 'guo' => '-17928', 'gun' => '-17931', 'gui' => '-17947', 'guang' => '-17950', 'guan' => '-17961', 'guai' => '-17964', 'gua' => '-17970', 'gu' => '-17988', 'gou' => '-17997', 'gong' => '-18012', 'geng' => '-18181', 'gen' => '-18183', 'gei' => '-18184', 'ge' => '-18201', 'gao' => '-18211', 'gang' => '-18220', 'gan' => '-18231', 'gai' => '-18237', 'ga' => '-18239', 'fu' => '-18446', 'fou' => '-18447', 'fo' => '-18448', 'feng' => '-18463', 'fen' => '-18478', 'fei' => '-18490', 'fang' => '-18501', 'fan' => '-18518', 'fa' => '-18526', 'er' => '-18696', 'en' => '-18697', 'e' => '-18710', 'duo' => '-18722', 'dun' => '-18731', 'dui' => '-18735', 'duan' => '-18741', 'du' => '-18756', 'dou' => '-18763', 'dong' => '-18773', 'diu' => '-18774', 'ding' => '-18783', 'die' => '-18952', 'diao' => '-18961', 'dian' => '-18977', 'di' => '-18996', 'deng' => '-19003', 'de' => '-19006', 'dao' => '-19018', 'dang' => '-19023', 'dan' => '-19038', 'dai' => '-19212', 'da' => '-19218', 'cuo' => '-19224', 'cun' => '-19227', 'cui' => '-19235', 'cuan' => '-19238', 'cu' => '-19242', 'cou' => '-19243', 'cong' => '-19249', 'ci' => '-19261', 'chuo' => '-19263', 'chun' => '-19270', 'chui' => '-19275', 'chuang' => '-19281', 'chuan' => '-19288', 'chuai' => '-19289', 'chu' => '-19467', 'chou' => '-19479', 'chong' => '-19484', 'chi' => '-19500', 'cheng' => '-19515', 'chen' => '-19525', 'che' => '-19531', 'chao' => '-19540', 'chang' => '-19715', 'chan' => '-19725', 'chai' => '-19728', 'cha' => '-19739', 'ceng' => '-19741', 'ce' => '-19746', 'cao' => '-19751', 'cang' => '-19756', 'can' => '-19763', 'cai' => '-19774', 'ca' => '-19775', 'bu' => '-19784', 'bo' => '-19805', 'bing' => '-19976', 'bin' => '-19982', 'bie' => '-19986', 'biao' => '-19990', 'bian' => '-20002', 'bi' => '-20026', 'beng' => '-20032', 'ben' => '-20036', 'bei' => '-20051', 'bao' => '-20230', 'bang' => '-20242', 'ban' => '-20257', 'bai' => '-20265', 'ba' => '-20283', 'ao' => '-20292', 'ang' => '-20295', 'an' => '-20304', 'ai' => '-20317', 'a' => '-20319', );

if( strtolower($code) != 'gb2312') $str = _U2_Utf8_Gb($str);

$_Res = '';

for($i=0; $i

    $_P = ord(substr($str, $i, 1));

    if($_P>160) {

        $_Q = ord(substr($str, ++$i, 1)); $_P = $_P*256 + $_Q - 65536;

    }

    $py = _Pinyin($_P, $_Data);

    if(!empty($py)){

        $_Res .= $first ? $py[0] : $py;

    }

}

$py = preg_replace("/[^a-zA-Z0-9]*/", '', $_Res);

$py = strtolower($py); //返回小写字母

return $py;

}

function _Pinyin(Num,_Data){

if($_Num>0 && $_Num<160 ){

    return chr($_Num);

}elseif($_Num<-20319 || $_Num>-10247){

    return '';

}else{

    foreach($_Data as $k=>$v){

        if($v<=$_Num) break;

    }

    return $k;

}

}

function _U2_Utf8_Gb($_C){

$_String = '';

if($_C < 0x80){

    $_String .= $_C;

}elseif($_C < 0x800) {

    $_String .= chr(0xC0 | $_C>>6);

    $_String .= chr(0x80 | $_C & 0x3F);

}elseif($_C < 0x10000){

    $_String .= chr(0xE0 | $_C>>12);

    $_String .= chr(0x80 | $_C>>6 & 0x3F);

    $_String .= chr(0x80 | $_C & 0x3F);

}elseif($_C < 0x200000) {

    $_String .= chr(0xF0 | $_C>>18);

    $_String .= chr(0x80 | $_C>>12 & 0x3F);

    $_String .= chr(0x80 | $_C>>6 & 0x3F);

    $_String .= chr(0x80 | $_C & 0x3F);

}

//加上"//ignore"使有不能转换的字符出现时不报错

return iconv('UTF-8', 'GB2312//ignore', $_String);

}

//================================================================

function yd_close_tags($html){

// strip fraction of open or close tag from end (e.g. if we take first x characters, we might cut off a tag at the end!)

$html = preg_replace('/<[^>]*$/','',$html); // ending with fraction of open tag

// put open tags into an array

preg_match_all('#<([a-z]+)(?: .*)?(?
相关标签:

上一篇: 网关

下一篇: zuul动态获取路由