PHP7.2+ each,count函数替代方法

each  这个函数在php7.2以后就弃用了  替代方法: function func_new_each(&$array){     $res = array();     $key = key($array);     if($key !== null){         next($array);         $res[1] = $res['value'] = $array[$key];         $res[0] = $res['key'] = $key;     }else{         $res = false;     }     return $res; } 实例: while (list ($key, $val) = $this->func_new_each($para)) {    if($key == "sign" || $key == "sign_type" || $val == "")continue;    else    $para_filter[$key] = $para[$key]; } 2. count  这个函数没有弃用,但是在7.2+上传递一个字符串参数的时候会报错:Warning:  count(): Parameter must be an array or an object that implements Countable 替代方法: function func_new_count($array_or_countable,$mode = COUNT_NORMAL){     if(is_array($array_or_countable) || is_object($array_or_countable)){         return count($array_or_countable, $mode);     }else{         return 0;     } }

中华人民共和国行政区划数据库/爬虫

包含中国省、市、县、街道、村/居委会5级数据(港、澳、台除外(统计局官网没有给出)),数据来源为国家统计局。 程序基于tp3.2.3编写,依赖Querylist3。 主要代码: /**  * @author Adam  * Time: 2018/6/15 14:50  */ public function sheng() {     $data = QueryList::Query($this->baseurl . "index.html", array("url" => array("td>a ", "href"), "name" => array("td>a", "text")), "", 'UTF-8', 'GB2312')->getData();     foreach ($data as $k => $v) {         $data[$k]["url"] = str_replace(".html", "", $v["url"]);         $data[$k]["saveid"] = $this->generate_full_id($data[$k]["url"]);         $res = $this->areamodel->where(array("area_id" => $data[$k]["url"]))->find();         if (empty($res)) {             $this->areamodel->data(array("area_id" => $data[$k]["url"], "area_pid" => 0, "area_name" => $data[$k]["name"], "level" => 1))->add();         }     }     echo json_encode($data);     die; } /**  * 二级 市   http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/14.html  * @author Adam  * Time: 2018/6/20 13:43  */ public function secondway() {     $toplevel = $this->areamodel->where(array("imported" => 0, "level" => 1))->order("area_id DESC")->find();     if (empty($toplevel)) {         echo "全部导入完毕,无需重新导入";         die;     }     $fatherid = $toplevel["area_id"];     $url = $this->baseurl . $toplevel["area_id"] . ".html";     $data = QueryList::Query($url, array("url" => array("td:eq(0)>a", "href"), "name" => array("td:eq(1)>a", "text")), "tr.citytr", 'UTF-8', 'GB2312')->getData();     foreach ($data as $k => $v) {         $data[$k]["url"] = str_replace(".html", "", $this->reg_real_id($v["url"])[0]);     }     M()->startTrans();     foreach ($data as $k1 => $v1) {         $res["area_id"] = $v1["url"];         $res["area_pid"] = $toplevel["area_id"];         $res["level"] = 2;         $res["area_name"] = $v1["name"];         if (!$this->areamodel->data($res)->add()) {             echo "循环导入失败" . M()->getLastSql();             die;             M()->rollback();         }     }     $this->areamodel->where(array("area_id" => $fatherid))->save(array("imported" => 1));     $sql = M()->getLastSql();     M()->commit();     echo "导入成功 " . $sql; … Read more

Github oauth登陆错误:Request forbidden by administrative rules

查看了文档  https://developer.github.com/v3/#user-agent-required 出现 Request forbidden by administrative rules错误的原因请求没有user-agent头  在Request header加一个 user-agent就ok了 。 我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1874o3fc4belz

Centos下 Nginx日志可视化分析

最近发现网站好像被扫描了,想从日志里面查看哪里的问题,研究了下goaccess这个工具 goaccess 官方网站:https://goaccess.io/ #安装epel源 yum install epel-release && yum -y update #安装goaccess yum -y install goaccess #终端分析 goaccess access.log -c #输出html静态文件  goaccess access.log -o report.html –log-format=COMBINED 附一个静态分析实例 http://p8pdat7ba.bkt.clouddn.com/lingnan.html

Mysql添加用户

#连接mysql mysql -u root -p #创建用户 create USER "adam"@"localhost" identified by '你的密码'; #查看用户列表 select CONCAT('User:',user,'@',host) from mysql.user; 输出 +——————————-+ | CONCAT('User:',user,'@',host) | +——————————-+ | User:adam@localhost           | | User:mysql.session@localhost  | | User:mysql.sys@localhost      | | User:root@localhost           | +——————————-+ 4 rows in set (0.00 sec) #分配权限   grant all privileges on wohuanicai.* to 'adam'@'localhost' identified by '你的密码';    #Over

Linux下Mysql每天自动备份数据库

#新建bash脚本文件 touch mysqlback.sh #编辑文件 vim mysqlback.sh #编写脚本 #!/bin/sh DB_USER="用户名" DB_PASS="密码" DB_HOST="localhost" DB_NAME="数据库名" BACK_DIR="/home/mysqlbackup" DATA=`date +%F` mysqldump –opt -u$DB_USER -p$DB_PASS -h$DB_HOST $DB_NAME | gzip  > $BACK_DIR/$DB_NAME_BACKUP_$DATA.sql.tar.gz 然后就是用crontab定时执行脚本文件  #进入编辑状态 crontab -e #计划每天凌晨3点1分执行  1 3 * * * /bin/bash /dir/mysqlback.sh

Mysql 查看所有用户

 #查看所有用户 select CONCAT('User:',user,'@',host) from mysql.user; 输出: | CONCAT('User:',user,'@',host) | +——————————-+ | User:adam@%                   | | User:root@127.0.0.1           | | User:root@::1                 | | User:adam@localhost           | | User:quan@localhost           | | User:root@localhost           | +——————————-+ 6 rows in set (0.00 sec) #查看用户权限 show grants for 'adam'@'localhost'; 输出: +————————————————————————————————————-+ | GRANT USAGE ON *.* TO 'adam'@'localhost' IDENTIFIED BY PASSWORD '*B2652B2C91E14A2B0088107BB28698EA57F78E01' | | GRANT ALL PRIVILEGES ON `wujin`.* TO 'adam'@'localhost'                                                     | +————————————————————————————————————-+ 2 rows in set (0.00 sec)

拼多多之多多客SDK

前天开始撸的多多客的SDK  拼多多开放平台官方地址  http://open.pinduoduo.com/#/index 多多进宝官方地址  http://jinbao.pinduoduo.com/#/ 开源地址  https://github.com/adamin1990/Duoduoke 使用方法: require_once("Duoduoke.php"); $config['client_id']="your client id"; $config['client_secret']="your client secret"; $config['duoduoke_redirect_url']="";  //可选 $config["access_token"]="";  //可选 $ddk=new Duoduoke($config); echo $ddk->api_goods_cat_get();