Random generation chinese characters

@return void
547136
protected function randomChinese()
    {
        if ( function_exists('mb_substr') )
        {
            $len = mb_strlen($this->chineseCharacters, 'utf-8');

            for ($i = 0; $i < $this->length; $i++)
            {
                $this->code .= mb_substr($this->chineseCharacters, mt_rand(0, $len - 1), 1, 'utf-8');
            }
        }
    }
1182961
public static function generateToken()
    {
        // Generate the token based on the current time, plus a random string.
        $token = time() . '.';

        // Start with an empty string.
        $length       = 32;
        $characterset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';

        // For the desired length, keep adding random characters from the character set.
        for ($i = 0; $i < $length; $i++) {
            $token .= $characterset[mt_rand(0, strlen($characterset) - 1)];
        }

        $sessions = [];

        if (isset($_SESSION['csrftokens'])) {
            $sessions = array_slice($_SESSION['csrftokens'], -50, 50);
        }

        // Add the token to the "token-basket", a place in which we store all the currently valid CSRF tokens.
        $sessions[] = $token;

        $_SESSION['csrftokens'] = $sessions;

        return $token;
    }
1222178
private function generateSalt()
    {
        $str = '';
        $length = 64;
        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(){}[]/|`,.?+-_=:;<> ';
        $count = strlen($chars);
        
        while ($length--) {
            $str .= $chars[mt_rand(0, $count - 1)];
        }
        
        return 'base64:' . base64_encode($str);
    }
800306
private function generate()
    {
        $characters = config('promocodes.characters');
        $mask = config('promocodes.mask');
        $promocode = '';
        $random = [];

        for ($i = 1; $i <= $this->length; $i++) {
            $character = $characters[rand(0, strlen($characters) - 1)];
            $random[] = $character;
        }

        shuffle($random);
        $length = count($random);

        $promocode .= $this->getPrefix();

        for ($i = 0; $i < $length; $i++) {
            $mask = preg_replace('/\*/', $random[$i], $mask, 1);
        }

        $promocode .= $mask;
        $promocode .= $this->getSuffix();

        return $promocode;
    }
337557
private function rewrite()
    {
        $ret = [];
        $ret ['control'] = 'index';
        $ret ['method'] = 'index';
        $ret ['action'] = 'index';
        $ret ['mod'] = '';
        $ret ['target'] = '';

        $uri = isset($_SERVER['REQUEST_URI']) ? trim($_SERVER['REQUEST_URI'], '?') : '';

        $base = isset($_SERVER['SCRIPT_NAME']) ? dirname($_SERVER['SCRIPT_NAME']) : '';
        if (false !== ($qm = strpos($uri, '?'))) {
            $uri = substr($uri, 0, $qm);
        }
        $rewrite = trim(substr($uri, strlen($base)), '/');
        $params = false !== strpos($rewrite, '/') ? explode('/', $rewrite) : ($rewrite ? [0 => $rewrite] : []);
        $ret['target'] = $ret['params'] = $params;

        $common_config = static::getCommonConfigVar('common');

        if (!empty($params) && count($params) > 0) {
            // 模块是否已经在common.cfg.php中定义
            $common_config['mods'][] = $this->modApiName;
            if (in_array($params[0], $common_config['mods'])) {
                // 支持 api的子模块
                if ($params[0] == $this->modApiName) {
                    if (count($params) > 3 && in_array($params[1], $common_config['mods'])) {
                        $ret['mod'] = $params[1];
                        $ret['control'] = !empty($params[2]) ? $params[2] : 'index';
                        $ret['action'] = !empty($params[3]) ? $params[3] : 'index';
                    } else {
                        $ret['mod'] = '';
                        $ret['control'] = !empty($params[1]) ? $params[1] : 'index';
                        $ret['action'] = !empty($params[2]) ? $params[2] : 'index';
                    }
                    $this->cmd = $ret['control'] . '.' . $ret['action'];
                } else {
                    $ret['mod'] = $params[0];
                    $ret['control'] = !empty($params[1]) ? $params[1] : 'index';
                    $ret['action'] = !empty($params[2]) ? $params[2] : 'index';
                }
            } else {
                $ret['mod'] = '';
                if (!isset($params[1]) || strpos($params[1], '.html') !== false) {
                    $params[1] = 'index';
                }
                $ret['control'] = !empty($params[0]) ? $params[0] : 'index';
                $ret['action'] = !empty($params[1]) ? $params[1] : 'index';
            }
        }
        $ret['method'] = $ret['action'];
        $this->ctrl = $ret['control'];
        $this->action = $ret['action'];
        $this->method = $ret['method'];
        $this->mod = $ret['mod'];
        $this->target = $ret['target'];
        return $ret;
    }
1094149
public function generateRandomPassword()
    {
        $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
        $pass = array();
        $alphaLength = strlen($alphabet) - 1;
        for ($i = 0; $i < 8; $i++) {
            $n = rand(0, $alphaLength);
            $pass[] = $alphabet[$n];
        }
        return implode($pass);
    }
89453
protected function drawText()
    {
        /**
         * 0 Numbers
         * 1 Pure English letters
         * 2 English letters & Numbers mixed
         * 3 chinese characters
         * 4 All mixed
         */

        switch($this->randomType)
        {
            case 0:
                $this->randomNumbers();
                break;

            case 1:
                $this->randomPureLetters();
                break;

            case 3:
                $this->randomChinese();
                break;

            case 4:
                $this->randomMixed();
                break;

            case 2:
            default:
                $this->randomLetters();
                break;
        }

        if (!$this->fontFile)
        {
            $this->fontFile = __DIR__ . '../../Fonts/verdana.ttf';
        }

        if (!file_exists($this->fontFile))
        {
            throw new \InvalidArgumentException('Font file ' . $this->fontFile . ' not found.');
        }

        $textColor = imagecolorallocate($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));

        $x = ($this->width - ($this->fontSize * $this->length)) / 2;
        $y = $this->fontSize + ($this->height - $this->fontSize) / 2;
        $fontFile = (is_array($this->fontFile)) ? $this->fontFile[array_rand($this->fontFile)] : $this->fontFile;

        imagettftext($this->image, $this->fontSize , mt_rand(-8, 8), $x, $y, $textColor, $fontFile, $this->code);
    }
588904
public function randomColor()
    {
        mt_srand((double)microtime() * 1000000);
        $c = '';
        while (strlen($c) < 6) {
            $c .= sprintf("%02X", mt_rand(0, 255));
        }
        return '#' . $c;
    }
421652
static function verifycode_chinese($font, $width = 180, $height = 60)
    {
        $length = 4;
        $angle = 45;
        $width = ($length * 45) > $width ? $length * 45 : $width;

        $im = imagecreatetruecolor($width, $height);
        $borderColor = imagecolorallocate($im, 100, 100, 100);                    //边框色
        $bkcolor = imagecolorallocate($im, 250, 250, 250);
        imagefill($im, 0, 0, $bkcolor);
        imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
        // 干扰
        for ($i = 0; $i < 5; $i++)
        {
            $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
            imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44,
                $fontcolor);
        }
        for ($i = 0; $i < 255; $i++)
        {
            $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
            imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor);
        }

        $code = '';
        for ($i = 0; $i < $length; $i++)
        {
            $fontcolor = imagecolorallocate($im, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120)); //这样保证随机出来的颜色较深。
            $codex =  RandomKey::getChineseCharacter(1);
            $code .= $codex;
            @imagettftext($im, mt_rand(16, 20), mt_rand(-$angle, $angle), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $font,
                $codex);
        }
        ob_start();
        ImagePng($im);
        $data = ob_get_clean();
        ImageDestroy($im);

        return array('code' => $code, 'image' => $data);
    }
777465
public static function str_safe_html(&$array)
    {
        if (is_array($array)) {
            foreach ($array as $key => $value) {
                if (!is_array($value)) {
                    //&,",',> ,< 转为html实体 &amp;,&quot;&#039;,&gt;,&lt;
                    $array[$key] = htmlspecialchars($value,ENT_QUOTES);
                } else {
                    self::str_safe_html($array[$key]);
                }
            }
        } else {
            $array = htmlspecialchars($array,ENT_QUOTES);
        }
    }
354408
public function makeSign()
    {
        //签名步骤一：按字典序排序参数
        ksort($this->values);
        $string = $this->ToUrlParams();
        //签名步骤二：在string后加入KEY
        $string = $string . "&key=".Config::getKEY();
        //签名步骤三：MD5加密
        $string = md5($string);
        //签名步骤四：所有字符转为大写
        $result = strtoupper($string);
        return $result;
    }
1136090
public static function random($length = 10, $allowedCharacters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {

        $charactersLength = self::length($allowedCharacters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $allowedCharacters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
1092388
function () {
	var trans = [
		[ "zh_tw" , "hello" ]
	];
		
	for ( var i in trans){
		console.log(i);
	}
	
	SR.DB.setData(i18nDB, {zh_tw:{hello: "哈囉"}}, function(){}, function(){});
	SR.DB.setData(i18nDB, {zh_tw:{say: "說"}}, function(){}, function(){});
	SR.DB.setData(i18nDB, {zh_tw:{see: "看"}}, function(){}, function(){});
	//SR.DB.setData("language", {"zh_tw":{"hello": "哈囉"}}, function(){}, function(){});
}
1297027
public function makeSign()
	{
		//签名步骤一：按字典序排序参数
		ksort($this->values);
		$string = $this->toUrlParams();
		//签名步骤二：在string后加入KEY
		$string = $string . '&key=' . Wxpay::getConfig('key');
		//签名步骤三：MD5加密
		$string = md5($string);
		//签名步骤四：所有字符转为大写
		$result = strtoupper($string);
		return $result;
	}
1309779
protected function randomLetters()
    {
        for ($i = 0; $i < $this->length; $i++)
        {
            $letters     = $this->letters[mt_rand(0, count($this->letters) - 1)];
            $this->code .= $letters[mt_rand(0, strlen($letters) - 1)];
        }
    }
1160398
private static function _buildSYLKCharacters()
	{
		self::$_SYLKCharacters = array(
			"\x1B 0"  => chr(0),
			"\x1B 1"  => chr(1),
			"\x1B 2"  => chr(2),
			"\x1B 3"  => chr(3),
			"\x1B 4"  => chr(4),
			"\x1B 5"  => chr(5),
			"\x1B 6"  => chr(6),
			"\x1B 7"  => chr(7),
			"\x1B 8"  => chr(8),
			"\x1B 9"  => chr(9),
			"\x1B :"  => chr(10),
			"\x1B ;"  => chr(11),
			"\x1B <"  => chr(12),
			"\x1B :"  => chr(13),
			"\x1B >"  => chr(14),
			"\x1B ?"  => chr(15),
			"\x1B!0"  => chr(16),
			"\x1B!1"  => chr(17),
			"\x1B!2"  => chr(18),
			"\x1B!3"  => chr(19),
			"\x1B!4"  => chr(20),
			"\x1B!5"  => chr(21),
			"\x1B!6"  => chr(22),
			"\x1B!7"  => chr(23),
			"\x1B!8"  => chr(24),
			"\x1B!9"  => chr(25),
			"\x1B!:"  => chr(26),
			"\x1B!;"  => chr(27),
			"\x1B!<"  => chr(28),
			"\x1B!="  => chr(29),
			"\x1B!>"  => chr(30),
			"\x1B!?"  => chr(31),
			"\x1B'?"  => chr(127),
			"\x1B(0"  => '€', // 128 in CP1252
			"\x1B(2"  => '‚', // 130 in CP1252
			"\x1B(3"  => 'ƒ', // 131 in CP1252
			"\x1B(4"  => '„', // 132 in CP1252
			"\x1B(5"  => '…', // 133 in CP1252
			"\x1B(6"  => '†', // 134 in CP1252
			"\x1B(7"  => '‡', // 135 in CP1252
			"\x1B(8"  => 'ˆ', // 136 in CP1252
			"\x1B(9"  => '‰', // 137 in CP1252
			"\x1B(:"  => 'Š', // 138 in CP1252
			"\x1B(;"  => '‹', // 139 in CP1252
			"\x1BNj"  => 'Œ', // 140 in CP1252
			"\x1B(>"  => 'Ž', // 142 in CP1252
			"\x1B)1"  => '‘', // 145 in CP1252
			"\x1B)2"  => '’', // 146 in CP1252
			"\x1B)3"  => '“', // 147 in CP1252
			"\x1B)4"  => '”', // 148 in CP1252
			"\x1B)5"  => '•', // 149 in CP1252
			"\x1B)6"  => '–', // 150 in CP1252
			"\x1B)7"  => '—', // 151 in CP1252
			"\x1B)8"  => '˜', // 152 in CP1252
			"\x1B)9"  => '™', // 153 in CP1252
			"\x1B):"  => 'š', // 154 in CP1252
			"\x1B);"  => '›', // 155 in CP1252
			"\x1BNz"  => 'œ', // 156 in CP1252
			"\x1B)>"  => 'ž', // 158 in CP1252
			"\x1B)?"  => 'Ÿ', // 159 in CP1252
			"\x1B*0"  => ' ', // 160 in CP1252
			"\x1BN!"  => '¡', // 161 in CP1252
			"\x1BN\"" => '¢', // 162 in CP1252
			"\x1BN#"  => '£', // 163 in CP1252
			"\x1BN("  => '¤', // 164 in CP1252
			"\x1BN%"  => '¥', // 165 in CP1252
			"\x1B*6"  => '¦', // 166 in CP1252
			"\x1BN'"  => '§', // 167 in CP1252
			"\x1BNH " => '¨', // 168 in CP1252
			"\x1BNS"  => '©', // 169 in CP1252
			"\x1BNc"  => 'ª', // 170 in CP1252
			"\x1BN+"  => '«', // 171 in CP1252
			"\x1B*<"  => '¬', // 172 in CP1252
			"\x1B*="  => '­', // 173 in CP1252
			"\x1BNR"  => '®', // 174 in CP1252
			"\x1B*?"  => '¯', // 175 in CP1252
			"\x1BN0"  => '°', // 176 in CP1252
			"\x1BN1"  => '±', // 177 in CP1252
			"\x1BN2"  => '²', // 178 in CP1252
			"\x1BN3"  => '³', // 179 in CP1252
			"\x1BNB " => '´', // 180 in CP1252
			"\x1BN5"  => 'µ', // 181 in CP1252
			"\x1BN6"  => '¶', // 182 in CP1252
			"\x1BN7"  => '·', // 183 in CP1252
			"\x1B+8"  => '¸', // 184 in CP1252
			"\x1BNQ"  => '¹', // 185 in CP1252
			"\x1BNk"  => 'º', // 186 in CP1252
			"\x1BN;"  => '»', // 187 in CP1252
			"\x1BN<"  => '¼', // 188 in CP1252
			"\x1BN="  => '½', // 189 in CP1252
			"\x1BN>"  => '¾', // 190 in CP1252
			"\x1BN?"  => '¿', // 191 in CP1252
			"\x1BNAA" => 'À', // 192 in CP1252
			"\x1BNBA" => 'Á', // 193 in CP1252
			"\x1BNCA" => 'Â', // 194 in CP1252
			"\x1BNDA" => 'Ã', // 195 in CP1252
			"\x1BNHA" => 'Ä', // 196 in CP1252
			"\x1BNJA" => 'Å', // 197 in CP1252
			"\x1BNa"  => 'Æ', // 198 in CP1252
			"\x1BNKC" => 'Ç', // 199 in CP1252
			"\x1BNAE" => 'È', // 200 in CP1252
			"\x1BNBE" => 'É', // 201 in CP1252
			"\x1BNCE" => 'Ê', // 202 in CP1252
			"\x1BNHE" => 'Ë', // 203 in CP1252
			"\x1BNAI" => 'Ì', // 204 in CP1252
			"\x1BNBI" => 'Í', // 205 in CP1252
			"\x1BNCI" => 'Î', // 206 in CP1252
			"\x1BNHI" => 'Ï', // 207 in CP1252
			"\x1BNb"  => 'Ð', // 208 in CP1252
			"\x1BNDN" => 'Ñ', // 209 in CP1252
			"\x1BNAO" => 'Ò', // 210 in CP1252
			"\x1BNBO" => 'Ó', // 211 in CP1252
			"\x1BNCO" => 'Ô', // 212 in CP1252
			"\x1BNDO" => 'Õ', // 213 in CP1252
			"\x1BNHO" => 'Ö', // 214 in CP1252
			"\x1B-7"  => '×', // 215 in CP1252
			"\x1BNi"  => 'Ø', // 216 in CP1252
			"\x1BNAU" => 'Ù', // 217 in CP1252
			"\x1BNBU" => 'Ú', // 218 in CP1252
			"\x1BNCU" => 'Û', // 219 in CP1252
			"\x1BNHU" => 'Ü', // 220 in CP1252
			"\x1B-="  => 'Ý', // 221 in CP1252
			"\x1BNl"  => 'Þ', // 222 in CP1252
			"\x1BN{"  => 'ß', // 223 in CP1252
			"\x1BNAa" => 'à', // 224 in CP1252
			"\x1BNBa" => 'á', // 225 in CP1252
			"\x1BNCa" => 'â', // 226 in CP1252
			"\x1BNDa" => 'ã', // 227 in CP1252
			"\x1BNHa" => 'ä', // 228 in CP1252
			"\x1BNJa" => 'å', // 229 in CP1252
			"\x1BNq"  => 'æ', // 230 in CP1252
			"\x1BNKc" => 'ç', // 231 in CP1252
			"\x1BNAe" => 'è', // 232 in CP1252
			"\x1BNBe" => 'é', // 233 in CP1252
			"\x1BNCe" => 'ê', // 234 in CP1252
			"\x1BNHe" => 'ë', // 235 in CP1252
			"\x1BNAi" => 'ì', // 236 in CP1252
			"\x1BNBi" => 'í', // 237 in CP1252
			"\x1BNCi" => 'î', // 238 in CP1252
			"\x1BNHi" => 'ï', // 239 in CP1252
			"\x1BNs"  => 'ð', // 240 in CP1252
			"\x1BNDn" => 'ñ', // 241 in CP1252
			"\x1BNAo" => 'ò', // 242 in CP1252
			"\x1BNBo" => 'ó', // 243 in CP1252
			"\x1BNCo" => 'ô', // 244 in CP1252
			"\x1BNDo" => 'õ', // 245 in CP1252
			"\x1BNHo" => 'ö', // 246 in CP1252
			"\x1B/7"  => '÷', // 247 in CP1252
			"\x1BNy"  => 'ø', // 248 in CP1252
			"\x1BNAu" => 'ù', // 249 in CP1252
			"\x1BNBu" => 'ú', // 250 in CP1252
			"\x1BNCu" => 'û', // 251 in CP1252
			"\x1BNHu" => 'ü', // 252 in CP1252
			"\x1B/="  => 'ý', // 253 in CP1252
			"\x1BN|"  => 'þ', // 254 in CP1252
			"\x1BNHy" => 'ÿ', // 255 in CP1252
		);
	}
1142321
public static function str_utf8_chinese_word_count($str = "")
    {
        $str = preg_replace(self::UTF8_SYMBOL_PATTERN, "", $str);
        return preg_match_all(self::UTF8_CHINESE_PATTERN, $str, $arr);
    }