zoukankan      html  css  js  c++  java
  • PHP7.1的几个新特性

    #以前多个变量赋值你可以这样写
    $a = 1;
    $b = 2;
    $c = 4;
    #或者相同值的你可以这样写 
    $a = $b = $c = [];
    #现在你可以这样为不同值的多个变量赋值
    [$a, $b, $c] = [1, 2, 3];
    `#以前用mcrypt写一个加密大概是这样
    public function encryptData($str, $key)
    {
        $block = mcrypt_get_block_size('des', 'ecb');
        $pad = $block - (strlen($str) % $block);
        $str .= str_repeat(chr($pad), $pad);
        $res = mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
        return strtoupper(bin2hex($res));
    }
    #现在你需要用openssl来替换了
    public function encryptData($str, $key)
    {
        $res = openssl_encrypt($str, 'DES-ECB', $key, OPENSSL_RAW_DATA);
        return strtoupper(bin2hex($res));
    }
    #以前用mcrypt写一个解密大概是这样
    public function decryptData($str, $key)
    {
        $str = strtolower($str);
        $str = pack('H*', $str);
        $decrypted = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
        $dec_s = strlen($decrypted);
        $padding = ord($decrypted[$dec_s - 1]);
        $decrypted = substr($decrypted, 0, -$padding);
        return $decrypted;
    }
    #现在也要用openssl替换了
    public function decryptData($str, $key)
    {
        $str = strtolower($str);
        $str = pack('H*', $str);
        $decrypted = openssl_decrypt($str,'DES-ECB', $key,OPENSSL_RAW_DATA);
        return $decrypted;
    }`
    `# 以前可以这样
    $num = 1 + 'abc323vccc';    //result 1;
    $num = 1 +'100abc';    //result 101;
    #现在你不能那样写了,将会得到这样的一个警告
    PHP warning:  A non-numeric value encountered on line 1```
  • 相关阅读:
    sklearn库学习笔记1——preprocessing库
    juypter notetbook
    信用卡欺诈
    matplotlib1
    python一行输入多个数
    pandas数据预处理
    pandas基础用法
    numpy简单用法2
    numpy 简单用法
    简单循环
  • 原文地址:https://www.cnblogs.com/samRoot/p/14207987.html
Copyright © 2011-2022 走看看