方案1

直接输入 pecl install mcrypt-snapshot
此方案的好处是不用改代码

方案2

<?php
class Encrypt{

    //base64_encode(openssl_random_pseudo_bytes(32));
    public $key    = "qK37s8Sb0uTDflFsHVwfWqZpySDXo6uHJVMGC3UOJsU=";
    //echo base64_encode(openssl_random_pseudo_bytes(16));
    public $iv    = "EXWPKlAyhkCjqMQkxkkyyA==";

    public function encrypt($value){

        $encrypted = openssl_encrypt($value, 'aes-256-cbc', base64_decode($this->key), OPENSSL_RAW_DATA, base64_decode($this->iv));
        return base64_encode($encrypted);
    }

    public function decrypt($string){
        $encrypted = base64_decode($string);
        $decrypted = openssl_decrypt($encrypted, 'aes-256-cbc', base64_decode($this->key), OPENSSL_RAW_DATA, base64_decode($this->iv));
        return $decrypted;
    }
}

//测试
$encrypt = new Encrypt();

$arr = [
    'a'   =>   '1',
    'b'   =>   '2'
];
$des = $encrypt->encrypt(json_encode($arr));
echo $encrypt->decrypt($des);
?>

php使用生成器读取超大文件

<?php function getLines($file) { $f = fopen($file, 'r'); try { while ($line = fgets($f)) { yield $line; ...

阅读全文

php获取字符串里面的图片,xpath方式

代码 <?php $html = <<<str <html> <head> <title>123</title> </head> <body> <img src=&quo...

阅读全文

Thinkphp5 in查询结果按照in里面的顺序排

或许有人会注意过,但我以前真不知道 SQL: select * from table where id IN (3,6,9,1,2,5,8,7); 这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序...

阅读全文

欢迎留言