javascript 常用函数转换成PHP代码处理
class js2php
{
public static function detect_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”);
text, $charsets));
return $encode;
}
public static function strlen()
{
static
func)) {
$func = ‘strlen’;
if (function_exists(‘mb_strlen’)) {
$func = ‘mb_strlen’;
}else if (function_exists(‘iconv_strlen’)) {
$func = ‘iconv_strlen’;
}
}
$args = func_get_args();
args[0]);
$args[1] = $encode;
return call_user_func_array($func, $args);
}
public static function substr()
{
static
func)) {
$func = ‘substr’;
if (function_exists(‘mb_substr’)) {
$func = ‘mb_substr’;
}else if (function_exists(‘iconv_substr’)) {
$func = ‘iconv_substr’;
}
}
$args = func_get_args();
args[0]);
$args[3] = $encode;
return call_user_func_array($func, KaTeX parse error: Expected 'EOF', got '}' at position 8: args); }̲ public static …str, KaTeX parse error: Expected '}', got 'EOF' at end of input: …=false) { if (!offset)
str, KaTeX parse error: Expected 'EOF', got '}' at position 10: offset); }̲ private static…string, &$offset)
{
string,
code >= 128) { //otherwise 0xxxxxxx
if ($code < 224)
code < 240)
code < 248) $bytesnumber = 4; //11110xxx
$codetemp =
bytesnumber > 2 ? 32 : 0) - (
i = 2; $i <= $bytesnumber; $i++) {
$offset ++;
string, $offset, 1)) - 128; //10xxxxxx
$codetemp = $codetemp*64 + $code2;
}
$code = $codetemp;
}
offset >= strlen($string)) $offset = -1;
return KaTeX parse error: Expected 'EOF', got '}' at position 7: code; }̲ public static …a, $b)
{
return (
$a >= 0
? $a >>
a & 0x7fffffff) >>
b - 1))
);
}
public static function charAt(
i)
{
return self::substr(
i,1);
}
public static function hex_md5(KaTeX parse error: Expected '}', got 'EOF' at end of input: …r){ return md5(str);
}
public static function toString(
dec=null){
if(
str);
return (string)$str;
}
public static function reverse(KaTeX parse error: Expected '}', got 'EOF' at end of input: … array_reverse(arr);
}
public static function string_lenght($string) {
return strlen(iconv(‘UTF-8’, ‘UTF-16LE’, $string)) / 2;
}
public static function charCodeAt($str, $index){
//not working!
str,
char, ‘UTF-8’))
{
char, ‘UTF-32BE’, ‘UTF-8’);
return hexdec(bin2hex($ret));
} else {
return null;
}
}
}
//一段由js代码转换而来的加密算法
<?php class mmb_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'); static public function strReverse($a) { $b='';$c = array(); for ($b = 0, $l = strlen($a); $b < $l; $b++) $c[] = $a{$b}; return implode('',array_reverse($c)); } static public function encrypt($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); return static::rnd($e ? static::strReverse(implode("",$g)) : implode("",$g), 4); } static public function to($a, $c) { $e = "" . js2php::toString(static::round($a + 88, $c),16); $f = $c - strlen($e); return $f > 0 ? static::$zero{$f - 1} . $e : $e; } static public function round($a, $b) { $c = 1 << 4 * $b; return 0 > $a ? $a % $c + $c : $a % $c; } static public function shuzi($a) { return preg_replace('/[^0-9]+/i', "",$a); } static public function zimu($a) { return preg_replace('/[^a-zA-Z]+/i', "",preg_replace('/https/', "http",strtolower($a))); } static public function rnd($a, $b) { return static::rd($b) . js2php::hex_md5($a) . static::rd(ceil(('0.'.mt_rand()) * 10)); } static public function rd($a) { $res = ""; for ( $i = 0; $i < $a; $i++) { $res .= static::$chars[ceil(('0.'.mt_rand()) * 35)]; } return $res; } } ?>对应的javascript代码如下: