2020-5-11 aslronx
来源:https://www.cnblogs.com/zhnblog/p/7163061.html2020-5-8 aslronx
来源 :https://www.cnblogs.com/ryanzheng/p/9086115.html
第一种方法是使用serialize,
第二种方法是使用print_r,
第三种方法是使用var_export,
本文章向大家介绍这三种方法是如何将数组写入到文件的,需要的朋友可以参考一下。
使用 serialize 将数组序列化,存储在文件中;调用时,再使用 unserialize 还原。
$file = './cache/phone.php'; $array = array( 'color' => array('blue', 'red', 'green'), 'size' => array('small', 'medium', 'large') ); //缓存 if (false !== fopen($file, 'w+')) { file_put_contents($file, serialize($array)); //写入缓存 } //读出缓存 $handle = fopen($file, 'r'); $cacheArray = unserialize(fread($handle, filesize($file)));
用print_r 将数组打印到txt文件中。
$b = array('m' => 'monkey', 'foo' => 'bar', 'x' => array('x', 'y', 'z')); $results = print_r($b, true); file_put_contents('filename.txt', print_r($b, true));
用var_export 直接将数组以完整数组的形式存储到文件中。
$file = './cache/phone.php'; $array = array( 'color' => array('blue', 'red', 'green'), 'size' => array('small', 'medium', 'large') ); //缓存 $text = '<?php $rows=' . var_export($array, true) . ';'; if (false !== fopen($file, 'w+')) { file_put_contents($file, $text); } else { echo '创建失败'; }
将对象完整的存储并追加到文件末尾
$file = "notic_" . date("Ymd") . ".log"; $ct = date("Y-m-d H:i:s", time()); file_put_contents($file, var_export($object,true)."\r\n", FILE_APPEND);
ps: 正常情况下输出到网页的数组会有限制,
php var_dump
函数对数组进行打印
时,对多维数组
中数组的层级越多越深层,子数组会不显示,只用省略号
代替。这样一来不便于程序的调试
。
php的var_dump函
数是php模块中xdebug模块所支持
的,所以接下来我们需要配置这个xdebug即可。
修改 php.ini
;设置显示最大的子节点数 xdebug.var_display_max_children=128 ;设置显示最大的字节数 xdebug.var_display_max_data=512 ;设置显示最大得层级(深度) xdebug.var_display_max_depth=15
然后重启 php 服务
systemctl reload php-fpm nginx
标签: PHP
2020-4-17 aslronx
转载自:https://www.cnblogs.com/yutaoyao/p/4621307.htmlfunction getFile($url, $save_dir = '', $filename = '', $type = 0) { if (trim($url) == '') { return false; } if (trim($save_dir) == '') { $save_dir = './'; } if (0 !== strrpos($save_dir, '/')) { $save_dir.= '/'; } //创建保存目录 if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) { return false; } //获取远程文件所采用的方法 if ($type) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $content = curl_exec($ch); curl_close($ch); } else { ob_start(); readfile($url); $content = ob_get_contents(); ob_end_clean(); } $size = strlen($content); //文件大小 $fp2 = @fopen($save_dir . $filename, 'a'); fwrite($fp2, $content); fclose($fp2); unset($content, $url); return array( 'file_name' => $filename, 'save_path' => $save_dir . $filename ); } $url = "http://www.baidu.com/img/baidu_jgylogo3.gif"; $save_dir = "down/"; $filename = "test.gif"; $res = getFile($url, $save_dir, $filename, 1); var_dump($res);
标签: PHP
2020-3-28 aslronx
https://www.bt.cn/btcode.html2020-3-23 aslronx
http://javathinker.cn/index.php/archives/107/
https://www.yiqucode.com/shiyonggongju-552.html
QYYBAC9D3J-eyJsaWNlbnNlSWQiOiJRWVlCQUM5RDNKIiwibGljZW5zZWVOYW1lIjoi6LaF57qnIOeoi+W6j+WRmCIsImFzc2lnbmVlTmFtZSI6IiIsImFzc2lnbmVlRW1haWwiOiIiLCJsaWNlbnNlUmVzdHJpY3Rpb24iOiIiLCJjaGVja0NvbmN1cnJlbnRVc2UiOmZhbHNlLCJwcm9kdWN0cyI6W3siY29kZSI6IklJIiwiZmFsbGJhY2tEYXRlIjoiMjAyMC0wMS0wNCIsInBhaWRVcFRvIjoiMjAyMS0wMS0wMyJ9LHsiY29kZSI6IkFDIiwiZmFsbGJhY2tEYXRlIjoiMjAyMC0wMS0wNCIsInBhaWRVcFRvIjoiMjAyMS0wMS0wMyJ9LHsiY29kZSI6IkRQTiIsImZhbGxiYWNrRGF0ZSI6IjIwMjAt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grUYSvkB/xVy/VoklPCK2h0f0GJxFjnye8NT1PAywoyl7RmiAVRE/EKwIDAQABo4GZMIGWMAkGA1UdEwQCMAAwHQYDVR0OBBYEFGEpG9oZGcfLMGNBkY7SgHiMGgTcMEgGA1UdIwRBMD+AFKOetkhnQhI2Qb1t4Lm0oFKLl/GzoRykGjAYMRYwFAYDVQQDDA1KZXRQcm9maWxlIENBggkA0myxg7KDeeEwEwYDVR0lBAwwCgYIKwYBBQUHAwEwCwYDVR0PBAQDAgWgMA0GCSqGSIb3DQEBCwUAA4ICAQAF8uc+YJOHHwOFcPzmbjcxNDuGoOUIP+2h1R75Lecswb7ru2LWWSUMtXVKQzChLNPn/72W0k+oI056tgiwuG7M49LXp4zQVlQnFmWU1wwGvVhq5R63Rpjx1zjGUhcXgayu7+9zMUW596Lbomsg8qVve6euqsrFicYkIIuUu4zYPndJwfe0YkS5nY72SHnNdbPhEnN8wcB2Kz+OIG0lih3yz5EqFhld03bGp222ZQCIghCTVL6QBNadGsiN/lWLl4JdR3lJkZzlpFdiHijoVRdWeSWqM4y0t23c92HXKrgppoSV18XMxrWVdoSM3nuMHwxGhFyde05OdDtLpCv+jlWf5REAHHA201pAU6bJSZINyHDUTB+Beo28rRXSwSh3OUIvYwKNVeoBY+KwOJ7WnuTCUq1meE6GkKc4D/cXmgpOyW/1SmBz3XjVIi/zprZ0zf3qH5mkphtg6ksjKgKjmx1cXfZAAX6wcDBNaCL+Ortep1Dh8xDUbqbBVNBL4jbiL3i3xsfNiyJgaZ5sX7i8tmStEpLbPwvHcByuf59qJhV/bZOl8KqJBETCDJcY6O2aqhTUy+9x93ThKs1GKrRPePrWPluud7ttlgtRveit/pcBrnQcXOl1rHq7ByB8CFAxNotRUYL9IF5n3wJOgkPojMy6jetQA5Ogc8Sm7RG6vg1yow==
2020-3-11 aslronx
// 获取当前域名 $request->domain() ; // 获取当前入口文件 $request->baseFile(); // 获取当前URL地址 不含域名 $request->url(); // 获取包含域名的完整URL地址 $request->url(true); // 获取当前URL地址 不含QUERY_STRING $request->baseUrl(); // 获取URL访问的ROOT地址 $request->root(); // 获取URL访问的ROOT地址包含域名 $request->root(true); // 获取URL地址中的PATH_INFO信息 $request->pathinfo(); // 获取URL地址中的PATH_INFO信息 不含后缀 $request->path(); // 获取URL地址中的后缀信息 $request->ext(); // 获取当前应用(模块) $request->module(); // 获取当前控制器 $request->controller(); // 获取当前操作名称 $request->action(); // 获取当前请求方法 $request->method(); // 获取当前请求访问地址 $request->type(); // 获取当前访问者 ip地址 $request->ip(); // 获取当前访问者 真实ip地址(防止代理) $request->ip(0,true); // 获取当前请求的id变量 $request->param('id'); // 获取当前请求的所有变量(已过滤) $request->param(); // 获取当前请求的所有变量(原始数据) $request->param(false); // 获取当前请求的所有变量(包含上传文件) $request->param(true); // 获取POST变量中的 id参数 $request->post('id'); // 获取所有的POST变量(已过滤) $request->post(); // 获取所有的POST变量(原始数据) $request->post(false); // 获取GET变量中的 id参数 $request->get('id'); // 获取所有的GET变量(已过滤) $request->get(); // 获取所有的GET变量(原始数据) $request->get(false); // 是否为 GET 请求 $request->isGet(); // 是否为 POST 请求 $request->isPost(); // 是否为 PUT 请求 $request->isPut(); // 是否为 DELETE 请求 $request->isDelete(); // 是否为 Ajax 请求 $request->isAjax(); // 是否为 Pjax 请求 $request->isPjax(); // 是否为手机访问 $request->isMobile(); // 是否为 HEAD 请求 $request->isHead(); // 是否为 Patch 请求 $request->isPatch(); // 是否为 OPTIONS 请求 $request->isOptions(); // 是否为 cli $request->isCli(); // 是否为 cgi $request->isCgi();
2019-11-23 aslronx
原文:http://www.thinkphp.cn/code/5227.html2018-8-26 aslronx
原文:http://lbsyun.baidu.com/index.php?title=lbscloud&qq-pf-to=pcqq.group2017-6-25 aslronx
原文:https://www.cnblogs.com/loveyoume/p/6076101.html