【PHP计算日期间隔天数】教程文章相关的互联网学习教程文章

php计算指定目录下文件占用空间的方法

本文实例讲述了php计算指定目录下文件占用空间的方法。分享给大家供大家参考。具体分析如下: php中可以通过 RecursiveDirectoryIterator 扩展 DirectoryIterator的getChildren() 方法提供访问子目录中的每一个元素的方法,下面的代码通过遍历访问目录下的所有文件,获取他们暂用的空间。 <?php $dir = new RecursiveDirectoryIterator(C:\wamp); $totalSize = 0; foreach (new RecursiveIteratorIterator($dir) as $file) {$total...

php计算两个日期相差天数的方法

本文实例讲述了php计算两个日期相差天数的方法。分享给大家供大家参考。具体实现方法如下: <?php /*** 求两个日期之间相差的天数* (针对1970年1月1日之后,求之前可以采用泰勒公式)* @param string $day1* @param string $day2* @return number*/ function diffBetweenTwoDays ($day1, $day2) {$second1 = strtotime($day1);$second2 = strtotime($day2);if ($second1 < $second2) {$tmp = $second2;$second2 = $second1;$second1...

php计算两个文件相对路径的方法

本文实例讲述了php计算两个文件相对路径的方法。分享给大家供大家参考。具体如下: 一、问题: 写一个php函数算出两个文件的相对路径。例如$a="/a/b/c/d/e.php"; $b="/a/b/12/34/c.php",B相对于A的相对路径是什么? 二、解决方法: <?php /*** 求$b相对于$a的相对路径* @param string $a* @param string $b* @return string*/ function getRelativePath ($a, $b) {$patha = explode(/, $a);$pathb = explode(/, $b);$counta = cou...

php计算函数执行时间的方法

本文实例讲述了php计算函数执行时间的方法。分享给大家供大家参考。具体如下: 我们可以通过在程序的前后分别记录开始和结束时间,两个时间差就是程序的执行时间。<?php $long_str = "this is a test to see how much time md5 function takes to execute over this string"; // start timing from here $start = microtime(true); // function to test $md5 = md5($long_str); $elapsed = microtime(true) - $start; echo "That t...

PHP计算指定日期所在周的开始和结束日期的方法

本文实例讲述了PHP计算指定日期所在周的开始和结束日期的方法。分享给大家供大家参考。具体实现方法如下: <html> <head> <title>计算一周开始结束日期</title> </head> <body> <form method="post" action="./index.html" enctype="utf-8"> <table><tr><td>输入年份</td><td><input name="year" type="text" maxlength="4" /></td></tr><tr><td>输入月份</td><td><input name="month" type="text" maxlength="2" /></td></tr><tr>...

php计算一个文件大小的方法

本文实例讲述了php计算一个文件大小的方法。分享给大家供大家参考。具体如下: <?phpfunction dirSize($directoty){$dir_size=0;if($dir_handle=@opendir($directoty)){while($filename=readdir($dir_handle)){$subFile=$directoty.DIRECTORY_SEPARATOR.$filename;if($filename==.||$filename==..){continue;}elseif (is_dir($subFile)){$dir_size+=dirSize($subFile);}elseif (is_file($subFile)){$dir_size+=filesize($subFile);...

php计算给定时间之前的函数用法实例

本文实例讲述了php计算给定时间之前的函数用法。分享给大家供大家参考。具体如下: 这里给定一个时间,计算这个时间在多久前,比如:2天前,1年前 <?php function prettyDate($date){$time = strtotime($date);$now = time();$ago = $now - $time;if($ago < 60){$when = round($ago);$s = ($when == 1)?"second":"seconds";return "$when $s ago";}elseif($ago < 3600){$when = round($ago / 60);$m = ($when == 1)?"minute":"minu...

php计算到指定日期还有多少天的方法

本文实例讲述了php计算到指定日期还有多少天的方法。分享给大家供大家参考。具体如下: function countdays($d) {$olddate = substr($d, 4);$newdate = date(Y) ."".$olddate;$nextyear = date(Y)+1 ."".$olddate;if($newdate > date("Y-m-d")){$start_ts = strtotime($newdate);$end_ts = strtotime(date("Y-m-d"));$diff = $end_ts - $start_ts;$n = round($diff / 86400);$return = substr($n, 1);return $return;}else{$start_...

php计算两个坐标(经度,纬度)之间距离的方法

本文实例讲述了php计算两个坐标(经度,纬度)之间距离的方法。分享给大家供大家参考。具体如下: 这里使用php计算两个坐标(经度,纬度)之间的距离,返回结果为米或者千米 function distance($lat1, $lng1, $lat2, $lng2, $miles = true) {$pi80 = M_PI / 180;$lat1 *= $pi80;$lng1 *= $pi80;$lat2 *= $pi80;$lng2 *= $pi80;$r = 6372.797; // mean radius of Earth in km$dlat = $lat2 - $lat1;$dlng = $lng2 - $lng1;$a = sin(...

php计算整个目录大小的方法

本文实例讲述了php计算整个目录大小的方法。分享给大家供大家参考。具体实现方法如下: /*** Calculate the full size of a directory** @author Jonas John* @version 0.2* @link http://www.jonasjohn.de/snippets/php/dir-size.htm* @param string $DirectoryPath Directory path*/ function CalcDirectorySize($DirectoryPath) {// I reccomend using a normalize_path function here// to make sure $DirectoryPa...

php计算整个mysql数据库大小的方法

本文实例讲述了php计算整个mysql数据库大小的方法。分享给大家供大家参考。具体如下: 这里用MB,KB或者GB的格式返回计算结果。 function CalcFullDatabaseSize($database, $db) {$tables = mysql_list_tables($database, $db);if (!$tables) { return -1; }$table_count = mysql_num_rows($tables);$size = 0;for ($i=0; $i < $table_count; $i++) {$tname = mysql_tablename($tables, $i);$r = mysql_query("SHOW TABLE STATUS F...

php计算多维数组中所有值总和的方法

本文实例讲述了php计算多维数组中所有值总和的方法。分享给大家供大家参考。具体实现方法如下: php 内置函数 array_sum() 函数返回数组中所有值的总和,只能返回一维数组的总和; 计算多维数组所有值的和就要自定义函数了; function get_sum($array) {$num = 0;foreach($array as $k => $v) {if(is_array($v)) {$num += get_sum($v);}}return $num + array_sum($array); } get_sum($array);希望本文所述对大家的php程序设计有所帮...

PHP计算加权平均数的方法

本文实例讲述了PHP计算加权平均数的方法。分享给大家供大家参考。具体如下: <form action="index.php" method="post"> 请输入你的课程的数量:<input type="text" name="course_number"/><br/> <input type="submit" value="submit"/> </form> <?php session_start();$course_number=$_POST["course_number"];$_SESSION["course_number"]=$course_number;$m=0;echo "<form action=result.php method=post>";for($i=0;$i<$course_nu...

php计算税后工资的方法

本文实例讲述了php计算税后工资的方法。分享给大家供大家参考。具体如下: 税前 税后 5000 3985 8000 6215 11000 8295 14000 10215 17000 12080 20000 13880 23000 15680 26000 17480 29000 19280 32000 21080 35000 22880 38000 24680 41000 26480 44000 28280 47000 30080 50000 31805 <?php function after_sleep($salary,$housefund_ratio=0.1,$person_insurance_ratio=.08,$medical_insurance_ratio=.04) {$...

php计算title标题相似比的方法

本文实例讲述了php计算title标题相似比的方法。分享给大家供大家参考。具体如下: <?php /*** @param string $title_1 题目1* @param string $title_2 题目2* @return float $percent 相似百分比*/ function title_similar($title_1,$title_2) {$title_1 = get_real_title($title_1);$title_2 = get_real_title($title_2);similar_text($title_1, $title_2, $percent);return $percent; } /*** php采集文章题目并去版权* @param s...