编程日志 | nohup.net

实践是检验真理的唯一标准

解决php警告Warning: Invalid argument supplied for foreach() in

在php中,如果foreach遍历的不是一个有效数组,会发出警告

“Warning: Invalid argument supplied for foreach() in ……”


解决方案:

加上一个非空判断即可。

foreach($arr as $key => $value)
{
}

开源web统计分析系统

开源,方便私有化部署和二次开发。

举例:

https://www.openwebanalytics.com/screenshots/

解决laravel response中文json反斜杠

中文被编码成Unicode,即反斜杠“\”十六进制,就很烦。

加上 JSON_UNESCAPED_UNICODE这个参数就好了,优雅。

return response()->jsonp($callback, $obj,200,[],JSON_UNESCAPED_UNICODE);

php laravel json反序列化输出xml格式

$result = '{"code":"Success","data":{"continent":"保留IP","country":"","zipcode":"","timezone":"","accuracy":"保留IP","owner":"","isp":"","source":"数据挖掘","areacode":"B1","adcode":"","asnumber":"","lat":"","lng":"","radius":"","prov":"","city":"","district":""},"charge":false,"msg":"查询成功","ip":"127.0.0.1","coordsys":"BD09"}';
$obj = json_decode($result, true);
if($format == 'xml'){
 return response()->xml($obj);
//     $data = [
//         'status' => 'success',
//         'data' => [
//             'first_name' => 'John',
//             'last_name' => 'Smith',
//         ]
//     ];
//     return response()->xml($data);
}

file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0

navicat SSH隧道报错: ssh tunnel:server does not support diffie-hellman-group1-sha1

解决方法如下:

1、编辑 /etc/ssh/sshd_config 在最后面添加:

KexAlgorithms diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1

jquery的innerText获取\t\n换行制表符问题

dom提示是innerText,但是用jquery的text()获取,会带上一些转义空白符号,如\t\t\t\\n\n\n。

经尝试,带个[0]就可以了——带上0,就是原生dom对象了。

$(this).find("p")[0].innerText


source 1.6 中不支持 diamond 运算符

一看就是JDK编译版本的配置问题,但IDEA改半天不管用,可能是pom.xml的优先级比较高吧。

在maven-compiler-plugin配置段里,加上

88

即可,最终:

jsonMapper格式化打印序列化对象

换行竖起来,美化打印,对于调试非常直观。废话少说,上代码:

JsonMapper jsonMapper = new JsonMapper();
System.out.println(jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(response));

参考:

宝塔自定义插件Demo增加IP地理位置为区县级和街道级

参考代码:

demo_main.py 里的get_logs函数里,增加:

        for log_item in log_list:
            log_str = log_item.get("log")
            left_ip = log_str.split('(')[0]
            right_op = log_str.split(')')[1]
            r = urlopen("https://api.ipplus360.com/ip/geo/v1/district/?key=YOUR_KEY&ip="+left_ip )
            json_str = r.read()
            r.close()
            middle = json_str
            response = json.loads(json_str)
            middle = response.get("data").get("prov") + response.get("data").get("city") + response.get("data").get("district")
            log_item["log"] = left_ip + middle + right_op
<< 1 2 3 4 5 > >>

Powered By Z-BlogPHP 1.7.2

© 2013-2022 nohup.net , All Rights Reserved. 豫ICP备20020372号-1