javascript 常用函数转换成PHP代码处理
对应的javascript代码如下:
classjs2php{ publicstaticfunctiondetect_encoding($text){ $charsets=array(“UTF-8”,“GB2312”,“GBK”,“BIG5”,“ASCII”,“EUC-JP”,‘KOI8-R’,“Shift_JIS”,“CP936”,“ISO-8859-1”,“JIS”,“eucjp-win”,“sjis-win”); encode= ( mbdetectencoding ( encode= (mb_detect_encoding(encode=(mbdetectencoding(text, $charsets)); return$encode; } publicstaticfunctionstrlen() { staticfunc=null ; if ( isnull ( func=null; if (is_null(func=null;if(isnull(func)) { $func=‘strlen’; if (function_exists(‘mb_strlen’)) { $func=‘mb_strlen’; }elseif (function_exists(‘iconv_strlen’)) { $func=‘iconv_strlen’; } } $args=func_get_args(); encode=self : : detectencoding ( encode=self::detect_encoding(encode=self::detectencoding(args[0]); $args[1] =$encode; returncall_user_func_array($func, $args); } publicstaticfunctionsubstr() { staticfunc=null ; if ( isnull ( func=null; if (is_null(func=null;if(isnull(func)) { $func=‘substr’; if (function_exists(‘mb_substr’)) { $func=‘mb_substr’; }elseif (function_exists(‘iconv_substr’)) { $func=‘iconv_substr’; } } $args=func_get_args(); encode=self : : detectencoding ( encode=self::detect_encoding(encode=self::detectencoding(args[0]); $args[3] =$encode; returncall_user_func_array($func, KaTeXparseerror: Expected'EOF', got'}'atposition8: args); }̲publicstatic…str, KaTeXparseerror: Expected'}', got'EOF'atendofinput: …=false) { if (!offset) offset=0 ; returnself : : ordutf8 ( offset=0; returnself::ordutf8(offset=0;returnself::ordutf8(str, KaTeXparseerror: Expected'EOF', got'}'atposition10: offset); }̲privatestatic…string, &$offset) { code=ord ( substr ( code=ord(substr(code=ord(substr(string, offset , 1 ) ) ; if ( offset,1)); if (offset,1));if(code>=128) { //otherwise 0xxxxxxxif ($code<224) bytesnumber=2 ; / /110xxxxxelseif ( bytesnumber=2; //110xxxxx else if (bytesnumber=2;//110xxxxxelseif(code < 240) b y t e s n u m b e r = 3 ; / / 1110 x x x x e l s e i f ( bytesnumber = 3; //1110xxxx else if (bytesnumber=3;//1110xxxxelseif(code < 248) $bytesnumber = 4; //11110xxx$codetemp=code−192− ( code-192- (code−192−(bytesnumber>2?32 : 0) - (bytesnumber>3?16 : 0 ) ; for ( bytesnumber>3?16 : 0); for (bytesnumber>3?16:0);for(i=2; $i<=$bytesnumber; $i++) { $offset++; code2=ord ( substr ( code2=ord(substr(code2=ord(substr(string, $offset, 1)) -128; //10xxxxxx$codetemp=$codetemp*64+$code2; } $code=$codetemp; } offset+=1 ; if ( offset+=1; if (offset+=1;if(offset>=strlen($string)) $offset=-1; returnKaTeXparseerror: Expected'EOF', got'}'atposition7: code; }̲publicstatic…a, $b) { return ( $a>=0?$a>>b : ( ( b : ((b:((a&0x7fffffff) >>b ) ∣ ( 0x40000000>> ( b) | (0x40000000>> (b)∣(0x40000000>>(b-1)) ); } publicstaticfunctioncharAt(a , a,a,i) { returnself::substr(a , a,a,i,1); } publicstaticfunctionhex_md5(KaTeXparseerror: Expected'}', got'EOF'atendofinput: …r){ returnmd5(str); } publicstaticfunctiontoString(str , str,str,dec=null){ if(dec==16 ) returndechex ( dec==16)returndechex(dec==16)returndechex(str); return (string)$str; } publicstaticfunctionreverse(KaTeXparseerror: Expected'}', got'EOF'atendofinput: …array_reverse(arr); } publicstaticfunctionstring_lenght($string) { returnstrlen(iconv(‘UTF-8’, ‘UTF-16LE’, $string)) /2; } publicstaticfunctioncharCodeAt($str, $index){ //not working!char=mbsubstr ( char=mb_substr(char=mbsubstr(str, index , 1 , ′UTF−8′ ) ; if ( mbcheckencoding ( index, 1, 'UTF-8'); if (mb_check_encoding(index,1, ′UTF−8′ );if(mbcheckencoding(char, ‘UTF-8’)) { ret=mbconvertencoding ( ret=mb_convert_encoding(ret=mbconvertencoding(char, ‘UTF-32BE’, ‘UTF-8’); returnhexdec(bin2hex($ret)); } else { returnnull; } } } //一段由js代码转换而来的加密算法<?phpclassmmb_d{ static$zero=array("0", "00", "000", "0000", "00000", "000000", "0000000", "00000000"); static$chars=array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); staticpublicfunctionstrReverse($a) { $b='';$c=array(); for ($b=0, $l=strlen($a); $b<$l; $b++) $c[] =$a{$b}; returnimplode('',array_reverse($c)); } staticpublicfunctionencrypt($a, $b, $e) { $a1=static::shuzi($a); $a2=static::zimu($a); $a=$a2 . $a1; $f=''; $g=array(); for ($f=0, $l=strlen($a); $f<$l; $f++) $g[] =static::to(js2php::charCodeAt($a,$f), $b); returnstatic::rnd($e?static::strReverse(implode("",$g)) : implode("",$g), 4); } staticpublicfunctionto($a, $c) { $e="" . js2php::toString(static::round($a+88, $c),16); $f=$c-strlen($e); return$f>0?static::$zero{$f-1} . $e : $e; } staticpublicfunctionround($a, $b) { $c=1<<4*$b; return0>$a?$a%$c+$c : $a%$c; } staticpublicfunctionshuzi($a) { returnpreg_replace('/[^0-9]+/i', "",$a); } staticpublicfunctionzimu($a) { returnpreg_replace('/[^a-zA-Z]+/i', "",preg_replace('/https/', "http",strtolower($a))); } staticpublicfunctionrnd($a, $b) { returnstatic::rd($b) . js2php::hex_md5($a) . static::rd(ceil(('0.'.mt_rand()) *10)); } staticpublicfunctionrd($a) { $res=""; for ( $i=0; $i<$a; $i++) { $res .=static::$chars[ceil(('0.'.mt_rand()) *35)]; } return$res; } } ?>