【php计算两个日期相隔多少年,多少月,多少天】教程文章相关的互联网学习教程文章

php计算一个文件大小的方法_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

本文实例讲述了PHP计算指定日期所在周的开始和结束日期的方法。分享给大家供大家参考。具体实现方法如下:计算一周开始结束日期<?php $time= $_POST[year].-.$_POST[month].-.$_POST[day]. 00:00:00; echo(你输入的时间是:.$time.); $lastday=date("Y-m-d",strtotime("$time Sunday")); echo(输入的时间星期第一天是:.date("Y-m-d",strtotime("$lastday - 6 days")).); echo(输入的时间星期最后一天是:.$lastday); ?>希望本文所...

php计算函数执行时间的方法_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; ech...

php计算两个坐标(经度,纬度)之间距离的方法_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

本文实例讲述了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":"minut...

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

本文实例讲述了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 st...

PHP计算加权平均数的方法_PHP

本文实例讲述了PHP计算加权平均数的方法。分享给大家供大家参考。具体如下:<?php session_start();$course_number=$_POST["course_number"];$_SESSION["course_number"]=$course_number;$m=0;echo "".""; ?><?php session_start();$score=array();$balance=array();$sum=0;$total_score=0;$result=0;for($i=0;$i<$_SESSION["course_number"];$i++){$score[$i]=$_POST["course".$i];}for($i=0;$i<$_SESSION["course_number"];$i++)...

php计算税后工资的方法_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) {$b...

php计算多维数组中所有值总和的方法_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计算整个mysql数据库大小的方法_PHP

本文实例讲述了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 FR...

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

本文实例讲述了php计算整个目录大小的方法。分享给大家供大家参考。具体实现方法如下:/*** Calculate the full size of a directory** @author Jonas John* @version 0.2* @param string $DirectoryPath Directory path*/ function CalcDirectorySize($DirectoryPath) {// I reccomend using a normalize_path function here// to make sure $DirectoryPath contains an ending slash// To display a good looking size ...

分享PHP计算两个日期相差天数的代码_PHP

本文实例讲述了php计算两个日期相差天数的方法。分享给大家供大家参考。具体实现方法如下:<?php $date1 = date( Y-m-d ); $date2 = "2015-12-04"; $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); printf("%d years, %d m...

php计算年龄精准到年月日_PHP

本文实例讲述了php计算年龄精准到年月日的方法。分享给大家供大家参考。具体如下:<?php/** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/class Age {/*** 计算年龄精准到年月日* @param type $birthday* @return array*/public function calAge($birthday) {list($byear, $bmonth, $bday) = ...

PHP计算数组中值的和与乘积的方法(array_sum与array_product函数)_PHP

本文实例讲述了PHP计算数组中值的和与乘积的方法。分享给大家供大家参考,具体如下: 一、概述: array_sum() 函数用于计算数组中所有值的和。 array_product() 函数用于计算数组中所有值的乘积。 二、使用示例: array_sum() PHP array_sum() 函数用于计算数组中所有值的和,以整数或浮点数返回计算结果,非数字的单元将视作 0 。 语法:number array_sum( array array )例子:<?php $arr_a = array(1, 2, 3, "a"); echo array_su...

PHP计算日期相差天数实例分析_PHP

本文实例分析了PHP计算日期相差天数的方法。分享给大家供大家参考,具体如下:<?PHP //今天与2016年10月27日相差多少天 $Date_1=date("Y-m-d"); $Date_2="2016-10-27"; $d1=strtotime($Date_1); $d2=strtotime($Date_2); $Days=round(($d1-$d2)/3600/24); echo "今天与2016年10月27日相差".$Days."天"; echo ""; //今天到2018年9月9日还有多少天 $Date_1=date("Y-m-d"); $Date_2="2018-09-09"; $d1=strtotime($Date_1); $d2=strto...