如何使用PHP查找两个日期之间的天数?
代码如下:
1 2 3 4 |
$now = time(); // or your date as well $your_date = strtotime("2010-01-31"); $datediff = $now - $your_date; echo round($datediff / (60 * 60 * 24)); |
走走停停,看日出!
如何使用PHP查找两个日期之间的天数?
代码如下:
1 2 3 4 |
$now = time(); // or your date as well $your_date = strtotime("2010-01-31"); $datediff = $now - $your_date; echo round($datediff / (60 * 60 * 24)); |
细心的朋友在查看php-php日志的时候会发现有时会出现下面的警告:
1 |
WARNING: <strong><span style="color: #ff0000;">[pool www]</span></strong> seemsbusy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, thereare 0 idle, and 29 totalchildren |
该信息是建议增加pm.start_servers数量,请注意下上面红色标注的[pool www], 不同配置可能这里会有差异,在具体修改的找到对应pool的配置文件即可;
首先找到所安装php-fpm的配置文件存放路径(注意:不同版本的php-fpm配置文件路径可能有细微的差别),我们可以通过phpinfo()打印查看。
1 2 3 4 |
pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 10 pm.max_spare_servers = 20 |
方法原理是通过搭建服务器激活,不过网上有许多搭建好的。
http://idea.imsxm.com (2016版)
注:不一定长期有效 继续阅读“phpstorm 激活大全(持续更新2018有效)”
首先在终端执行下面的命令安装Nginx 服务:
1 |
sudo apt-get install nginx |
启动nginx服务:
1 |
sudo /etc/init.d/nginx start |
在终端运行 hostname -I
命令获得树莓派的IP地址,然后在浏览器访问有输出Welcome to nginx! 即表示安装启动成功。 继续阅读“树莓派搭建Nginx+PHP服务器”
通过header content-type设置页面编码为utf-8:
1 2 3 |
<?php header('Content-Type: text/html; charset=utf-8'); ?> |
通过header location设置页面跳转:
1 2 3 |
<?php header('Location: https://www.dustit.me/'); ?> |
页面缓存设置:
1 2 3 4 |
<?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> |
删除数组元素有不同的方法,可以根据具体的需要选择不同的方法。
注意:当您使用unset()方法时,数组Key值不会更改。 如果要重新编号键,您可以在unset()之后使用array_values(),它将所有键转换为从0开始的数值枚举键。
1 2 3 4 5 6 |
<?php $array = array(0 => "a", 1 => "b", 2 => "c"); unset($array[1]); //↑ 需要删除的键 ?> |
输出
1 2 3 4 |
Array ( [0] => a [2] => c ) |
一个解决方案是使用end和key的组合:
end()将数组的内部指针提升到最后一个元素,并返回其值。
key()返回当前数组位置的索引元素。
所以,这样的代码的一部分应该做的诀窍:
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php $array = array( 'first' => 123, 'second' => 456, 'last' => 789, ); end($array); // move the internal pointer to the end of the array $key = key($array); // fetches the key of the element pointed to by the internal pointer var_dump($key); ?> |
输出:
1 |
string 'last' (length=4) |
另一种更简单的获取最后一个元素的方法:
1 2 3 |
<?php echo $array[count($array) - 1]; ?> |
php文档中对缓冲区有这样的描述:
As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string
那我们是不是能利用这一点将var_dump的结果捕获且赋值给某变量呢?
测试代码:
1 2 3 4 5 |
<?php ob_start(); var_dump($someVar); $result = ob_get_clean(); ?> |