function is_idcard( $id )
    {
        $id = strtoupper($id);
        $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
        $arr_split = array();
        if(!preg_match($regx, $id))
        {
            return FALSE;
        }
        if(15==strlen($id)) //检查15位
        {
            $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";

            @preg_match($regx, $id, $arr_split);
            //检查生日日期是否正确
            $dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
            if(!strtotime($dtm_birth))
            {
                return FALSE;
            } else {
                return TRUE;
            }
        }
        else      //检查18位
        {
            $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
            @preg_match($regx, $id, $arr_split);
            $dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
            if(!strtotime($dtm_birth)) //检查生日日期是否正确
            {
                return FALSE;
            }
            else
            {
                //检验18位身份证的校验码是否正确。
                //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
                $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
                $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
                $sign = 0;
                for ( $i = 0; $i < 17; $i++ )
                {
                    $b = (int) $id{$i};
                    $w = $arr_int[$i];
                    $sign += $b * $w;
                }
                $n = $sign % 11;
                $val_num = $arr_ch[$n];
                if ($val_num != substr($id,17, 1))
                {
                    return FALSE;
                }
                else
                {
                    return TRUE;
                }
            }
        }

    }
$idc=is_idcard("身份证号码"); 
if($idc){echo "正确";}else{echo "错误";}

input输入框实时显示计算,不能有多余的.,结果保留两位小数

<input id="task_num" type="text" oninput = "handleMoney(this,0);">
<input id="task_price" type="text" oninput = "handleMoney(this,1);">
function handleMoney(obj,type){//0代表不要小数,1代表代表保留两位小数
        if(type == 0){
            obj.value = obj.value.replace(/[^\d]/g, '');//没有.
            obj.value = obj.value.replace(/\.{2,}/g, '.');
            obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
            //(\d\d)代表保留两位,(\d)代表保留一位,以此类推....
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
            if (obj.value.indexOf('.') < 0 && obj.value != '') {
                obj.value = parseFloat(obj.value);
            }
            if ((obj.value.length == 1 && obj.value == '.') || obj.value.substring(0,1) == '.') {
                obj.value = '';
            }
        }else{
            obj.value = obj.value.replace(/[^\d.]/g, '');//有.
            obj.value = obj.value.replace(/\.{2,}/g, '.');//2即两位
            obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
            if (obj.value.indexOf('.') < 0 && obj.value != '') {
                obj.value = parseFloat(obj.value);
            }
            if ((obj.value.length == 1 && obj.value == '.') || obj.value.substring(0,1) == '.') {
                obj.value = '';
            }
        }

        var value1 = $('#task_num').val();
        var value2 = $('#task_price').val();
        if(value1 && value2){
            var res = value1*value2;
            $('#money').val(res.toFixed(2));
        }else{
            $('#money').val(0);
        }
    }

public function pingyinFirstChar($sourcestr)
    {

        $returnstr = '';
        $i = 0;
        $n = 0;
        $str_length = strlen($sourcestr);//字符串的字节数

        while ($i <= $str_length) {

            $temp_str = substr($sourcestr, $i, 1);
            $ascnum = Ord($temp_str);//得到字符串中第$i位字符的ascii码

            if ($ascnum >= 224) { //如果ASCII位高与224,
                $returnstr = $returnstr . $this->getHanziInitial(substr($sourcestr, $i, 3)); //根据UTF-8编码规范,将3个连续的字符计为单个字符
                $i = $i + 3;//实际Byte计为3
            } else if ($ascnum >= 192) { //如果ASCII位高与192,
                $returnstr = $returnstr . $this->getHanziInitial(substr($sourcestr, $i, 2)); //根据UTF-8编码规范,将2个连续的字符计为单个字符
                $i = $i + 2;//实际Byte计为2
            } else if ($ascnum >= 65 && $ascnum <= 90) { //如果是大写字母,
                $returnstr = $returnstr . substr($sourcestr, $i, 1);
                $i = $i + 1;//实际的Byte数仍计1个
            } else { //其他情况下,包括小写字母和半角标点符号,
                $returnstr = $returnstr . strtoupper(substr($sourcestr, $i, 1)); //小写字母转换为大写
                $i = $i + 1;//实际的Byte数计1个
            }
        }

        return $returnstr;
    }

    public function getHanziInitial($s0)
    {

        if (ord($s0) >= "1" and ord($s0) <= ord("z")) {
            return strtoupper($s0);
        }
        $s = iconv("UTF-8", "gb2312//IGNORE", $s0); // 不要转换成GB2312内没有的字符哦,^_^
        // var_dump($s);exit;

        $asc = @ord($s[0]) * 256 + @ord($s[1]) - 65536;
        if ($asc >= -20319 and $asc <= -20284) return "A";
        if (in_array($asc, [])) return "A";
        if ($asc >= -20283 and $asc <= -19776) return "B";
        if (in_array($asc, [-8791, -5941])) return "B";
        if ($asc >= -19775 and $asc <= -19219) return "C";
        if (in_array($asc, [-4916])) return "C";
        if ($asc >= -19218 and $asc <= -18711) return "D";
        if (in_array($asc, [])) return "D";
        if ($asc >= -18710 and $asc <= -18527) return "E";
        if (in_array($asc, [])) return "E";
        if ($asc >= -18526 and $asc <= -18240) return "F";
        if (in_array($asc, [-6662])) return "F";
        if ($asc >= -18239 and $asc <= -17923) return "G";
        if (in_array($asc, [-8721, -2824, -5681])) return "G";
        if ($asc >= -17922 and $asc <= -17418) return "H";
        if (in_array($asc, [-8721])) return "H";
        if ($asc >= -17417 and $asc <= -16475) return "J";
        if (in_array($asc, [-5671, -8795, -65536, -8966, -8772, -6712])) return "J";
        if ($asc >= -16474 and $asc <= -16213) return "K";
        if (in_array($asc, [])) return "K";
        if ($asc >= -16212 and $asc <= -15641) return "L";
        if (in_array($asc, [-2069, -5715])) return "L";
        if ($asc >= -15640 and $asc <= -15166) return "M";
        if (in_array($asc, [-8786, -7512])) return "M";
        if ($asc >= -15165 and $asc <= -14923) return "N";
        if (in_array($asc, [])) return "N";
        if ($asc >= -14922 and $asc <= -14915) return "O";
        if (in_array($asc, [])) return "O";
        if ($asc >= -14914 and $asc <= -14631) return "P";
        if (in_array($asc, [-8718, -5951])) return "P";
        if ($asc >= -14630 and $asc <= -14150) return "Q";
        if (in_array($asc, [-2072, -8967])) return "Q";
        if ($asc >= -14149 and $asc <= -14091) return "R";
        if (in_array($asc, [])) return "R";
        if ($asc >= -14090 and $asc <= -13319) return "S";
        if (in_array($asc, [-8744, -8795])) return "S";
        if ($asc >= -13318 and $asc <= -12839) return "T";
        if (in_array($asc, [-8979])) return "T";
        if ($asc >= -12838 and $asc <= -12557) return "W";
        if (in_array($asc, [-8789])) return "W";
        if (in_array($asc, [-4869, -9016, -8529])) return "X";
        if ($asc >= -12556 and $asc <= -11848) return "X";
        if ($asc >= -11847 and $asc <= -11056) return "Y";
        if (in_array($asc, [-5930, -5159])) return "Y";
        if ($asc >= -11055 and $asc <= -10247) return "Z";
        if (in_array($asc, [-5717])) return "Z";
        return 'a'; //$s0 是 返回原字符,不作转换。(标点、空格、繁体字都会直接返回)
    }

很多用户使用七牛过程中有将资源从一个空间复制到另外一个空间的需求,这种情况下可用我们的sdk先list出所有的文件然后在批量复制,但是使用同步工具进行同步的方法是最快的,下面详解这种方法:

1.下载七牛的同步工具qshell: http://developer.qiniu.com/docs/v6/tools/qshell.html

2.登录到当前账户下 qshell account 《AK》 《SK》

3.使用listbucket命令列举出需要复制的当前空间 https://github.com/qiniu/qshell/wiki/listbucket
使用的命令 qshell listbucket 《Bucket》 [《Prefix》] 《ListBucketResultFile》
本例中的命令如下:
qshell listbucket copytest1 cp.txt

4.上步操作后会在当前目录下生成一个名为cp.txt的list文件列表,格式如下:

photo-2.jpg 109787 FvaTV7fZz6G_1W6WyzQdktMbqPuv 14526031733113853 image/jpeg 
photo3.jpg 256148 Fq3vt4smenbZ_ev-iba2Yukx5d9B 14526031741765437 image/jpeg 
photo4.jpg 194277 FtxVybqCmEm_ZWEJ6l2vg-qKbzWh 14526031747456153 image/jpeg 
photo5.jpg 131862 FslN6hs8puP_ksS6KYCl0OxgcWoO 14526031770721477 image/jpeg
5.而我们只需要得到最前面的文件key就可以了,可以使用一条awk字符处理命令就可以了
cat cp.txt | awk '{print $1}' >cpp.txt

这样就在当前目录生成了一个如下只包含文件的key的txt文件cpp.txt

photo-2.jpg
photo3.jpg
photo4.jpg
photo5.jpg
6.使用batchcopy命令将文件同步到需要复制的空间里面 https://github.com/qiniu/qshell/wiki/batchcopy
这里直接给出命令,将copytest1空间文件复制到copytest2空间
qshell batchcopy copytest1 copytest2 cpp.txt
实际过程中可能会让确认操作,相应确认下就可以了,执行结果参考如下:
~/tools » qshell batchcopy copytest1 copytest2 cpp.txt 
<DANGER> Input gcafcc to confirm operation: gcafcc 
All Copyed!

至此文件就成功从copytest1空间文件复制到copytest2空间了,当然复制过程中也可以实现对文件的命名操作,具体可以参考https://github.com/qiniu/qshell/wiki/batchcopy

文章转自

一、打开3306端口

如果您的操作系统为CentOS系列
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
service iptables save #保存iptables规则
如果您的操作系统为Ubuntu/Debian系列
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
iptables-save > /etc/iptables.up.rules #保存iptables规则

二、数据库授权

MySQL8.0版本
# mysql -uroot -p
 MySQL [(none)]> create user db_user@'%' identified by 'db_pass'; #创建用户
 MySQL [(none)]> grant all privileges on db_name.* to db_user@'%' with grant option; #授权
 MySQL [(none)]> exit; #退出数据库控制台,特别注意有分号
其余MySQL版本
# mysql -uroot -p
 MySQL [(none)]> grant all privileges on db_name.* to db_user@'%' identified by 'db_pass'; #授权语句,特别注意有分号
 MySQL [(none)]> flush privileges;
 MySQL [(none)]> exit; #退出数据库控制台,特别注意有分号
PS:如果想让这个用户管理所有的表而不是某个表:db_name.* 改为 *.* 即可;