php strtotime()计算今天与指定日期之天数
php教程 strtotime()计算今天与指定日期之天数
$date1 = strtotime('2011-04-30'); //把日期转换成时间戳
$date2 = time(); //取当前时间的时间戳
$nowtime=strftime("%y年-%m月-%d日 ",$date2); //格式化输出日期
$days=round(($date1-$date2)/3600/24); //四舍五入
echo "今天是<font color="red">".$nowtime."</font>";
echo "<br/>距".strftime("%y年-%m月-%d日 ",$date1)."还有<font colr="red">".$days."</font>天";
echo date("y-m-d h:i:s",strtotime("now")). "<br />";
echo date("y-m-d h:i:s",strtotime("10 september 2000")). "<br />";
echo date("y-m-d h:i:s",strtotime("+2 day")). "<br />";
echo date("y-m-d h:i:s",strtotime("+1 week")). "<br />";
echo date("y-m-d h:i:s",strtotime("+1 week 2 days 4 hours 2 seconds")). "<br />";
echo date("y-m-d h:i:s",strtotime("next thursday")). "<br />";
echo date("y-m-d h:i:s",strtotime("last monday")). "<br />";
echo date("y-m-d h:i:s",strtotime("+3 day",strtotime('2001-01-01')));
检测数据类型php教程函数集
检测数据类型即对数据类型进行检测,判断所检测类型是否属于检测类型,符合则返回真,否则返回假。检测数据类型定义如下:
is_bool
是否为布尔类型,例,is_bool(srue) is_bool(false)
is_string
是否为字符串型,例,is_string(‘string’) is_string(1234)
is_float/double
是否为浮点型,例,is_float(3.1415) is_float(‘3.1415’)
is_integer/int
是否为整型,例,is_integer(34) is_integer(‘34’)
is_null
是否为空值,例,is_null(null)
is_array
是否为数组,例,is_array($arr)
is_object
是否为一个对象,例,is_object($obj)
is_numeric
是否为数字或由数字组成的字符串,例,is_numeric(‘5’) is_numeric(‘bcc110’)
示例
<?php
$boo="1234567890";
if(is_numeric($boo))
echo "变量boo属由数字组成的字符串类型:".$boo;
else
echo"无法判断";
?>
php教程中checkbox值获取,显示,多选值获取
最简单checkbox获取值代码
<html>
<head>
<title>checkbox demo</title>
</head>
<body>
<h1>checkbox demo</h1>
<h3>demonstrates checkboxes</h3>
<form action ="handleformcheckbox.php">
<ul>
<li><input type ="checkbox" name ="chkfries" value ="11.00">fries</li>
<li><input type ="checkbox" name ="chksoda" value ="12.85">soda</li>
<li><input type ="checkbox" name ="chkshake" value ="1.30">shake</li>
<li><input type ="checkbox" name ="chkketchup" value =".05">ketchup</li>
</ul>
<input type ="submit">
</form>
</body>
</html>
<!-- handleformcheckbox.php
<html>
<head>
<title>checkbox demo</title>
</head>
<body>
<h3>demonstrates reading checkboxes</h3>
<?
print <<<here
chkfries: $chkfries <br>
chksoda: $chksoda <br>
chkshake: $chkshake <br>
chkketchup: $chkketchup <br>
<hr>
here;
$total = 0;
if (!empty($chkfries)){
print ("you chose fries <br>");
$total = $total + $chkfries;
}
if (!empty($chksoda)){
print ("you chose soda <br>");
$total = $total + $chksoda;
}
if (!empty($chkshake)){
print ("you chose shake <br>");
$total = $total + $chkshake;
}
if (!empty($chkketchup)){
print ("you chose ketchup <br>");
$total = $total + $chkketchup;
}
print "the total cost is $$total";
?>
</body>
</html>
-->
实例
<html>
<head>
<title>using default checkbox values</title>
</head>
<body>
<?php
$food = $_get[food];
$self = htmlentities($_server['php_self']);
if (!empty($food)) {
echo "the foods selected are:<br />";
foreach($food as $foodstuf)
{
echo "<strong>".htmlentities($foodstuf)."</strong><br />";
}
}
else
{
echo ("<form action="$self" ");
echo ('method="get">
<fieldset>
<label>italian <input type="checkbox" name="food[]" value="italian" />
</label>
<label>mexican <input type="checkbox" name="food[]" value="mexican" />
</label>
<label>chinese <input type="checkbox" name="food[]" value="chinese"
checked="checked" /></label>
</fieldset>
<input type="submit" value="go!" >');
}
?>
</body>
</html>
多选checkbox
<?php
$options = array('option 1', 'option 2', 'option 3');
$valid = true;
if (is_array($_get['input'])) {
$valid = true;
foreach($_get['input'] as $input) {
if (!in_array($input, $options)) {
$valid = false;
}
}
if ($valid) {
//process input
}
}
?>
实例checkbox多值获取
<html>
<head>
<title>using default checkbox values</title>
</head>
<body>
<?php
$food = $_get["food"];
if (!empty($food)){
echo "the foods selected are: <strong>";
foreach($food as $foodstuff){
echo '<br />'.htmlentities($foodstuff);
}
echo "</strong>.";
}
else {
echo ('
<form action="'. htmlentities($_server["php_self"]).'" method="get">
<fieldset>
<label>
italian
<input type="checkbox" name="food[]" value="italian" />
</label>
<label>
mexican
<input type="checkbox" name="food[]" value="mexican" />
</label>
<label>
chinese
<input type="checkbox" name="food[]" value="chinese" checked="checked" />
</label>
</fieldset>
<input type="submit" value="go!" />
</form> ');
}
?>
</body>
</html>
$globals --- 保存所有全局变量(只在当前页面中的) get_defined_vars() --- 返回由所有已定义变量所组成的数组(包括全局变量,超全局变量等) get_defined_constants() --- 返回由所有已定义常量所组成的数组
function cleanglobal($global_array, $arg, $specialchars = true, $default = null) {
if(key_exists($arg, $global_array) && $global_array[$arg] != null && $global_array[$arg] != "") {
if($specialchars) {
return htmlspecialchars($global_array[$arg]);
} else {
return $global_array[$arg];
}
} else {
return $default;
}
}
table of contents
superglobals — superglobals are built-in variables that are always available in all scopes
$globals — references all variables available in global scope
$_server — server and execution environment information
$_get — http get variables
$_post — http post variables
$_files — http file upload variables
$_request — http request variables
$_session — session variables
$_env — environment variables
$_cookie — http cookies
$php教程_errormsg — the previous error message
$http_raw_post_data — raw post data
$http_response_header — http response headers
$argc — the number of arguments passed to script
$argv — array of arguments passed to script
使用substr_count()函数检索字符出现的次数
获取指定字符在字符串中出现的次数
语法:substr_count(haystack,needle)
使用substr_count()函数获取特定字符在字符串中出现的次数实例如下:
<?php教程
echo substr_count(“zero的php自学手册”,”的”);
echo “<br>”;
echo substr_count(“www.111cn.net”,”o”);
echo “<br>”;
echo substr_count(“1033114118′,”1′);
?>
实例结果:
1
2
5
参数 | 描述 |
---|---|
string | 必需。规定要检查的字符串。 |
replacement | 必需。规定要插入的字符串。 |
start | 可选。规定在字符串中何处开始搜索。 |
charlist | 可选。规定搜索的长度。 |
相关文章
- 一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
- 本篇文章主要是对C#中获取目前月份的天数的三种方法进行了详细的总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助...2020-06-25
- 本文实例讲述了php计算两个日期相差天数的方法。...2015-03-15
- 这篇文章主要介绍了PostgreSQL 字符串处理与日期处理操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-01
- moment是一款多语言支持的日期处理类库, 在vue中如何使用呢?这篇文章主要给大家介绍了关于vue之moment使用的相关资料,需要的朋友可以参考下...2021-05-13
- 实例讲解之前,先来介绍几个核心函数: mktime 函数 mktime() 函数返回一个日期的 Unix 时间戳。 参数总是表示 GMT 日期,因此 is_dst 对结果没有影响。 参数可以从右到左依次空着,空着的参数会被设为相应的当前 GMT 值。...2015-11-08
- 这篇文章主要介绍了C#实现将字符串转换成日期格式的方法,涉及C#操作时间及字符串的相关技巧,非常简单实用,需要的朋友可以参考下...2020-06-25
- 分享一个利用php根据日期或时间戳获取相应的干支纪年,生肖和星座信息的函数方法,具体函数代码以及使用方法如下: /** 判断干支、生肖和星座 */ function birthext($birth){ if(strstr($birth,'-')===false&&strlen($bi...2015-10-21
java8时间 yyyyMMddHHmmss格式转为日期的代码
这篇文章主要介绍了java8时间 yyyyMMddHHmmss格式转为日期的代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-17- 这篇文章主要介绍了C#判断日期是否到期的方法,是C#程序设计中非常实用的技巧,需要的朋友可以参考下...2020-06-25
- 在本篇内容中小编给大家整理了关于C#比较日期的方法和相关知识点,有需要的朋友们学习下。...2020-06-25
- 最近在做一个列表的时候,涉及到时间格式化操作。本文主要介绍了微信小程序wxs日期时间处理的实现示例,分享给大家,感兴趣的可以了解一下...2021-07-22
jQuery DateTimePicker 日期和时间插件示例
jQuery UI很强大,其中的日期选择插件Datepicker是一个配置灵活的插件,这篇文章主要介绍了jQuery DateTimePicker 日期和时间插件示例,有兴趣的可以了解一下。...2017-01-26- 这篇文章主要介绍了sql通过日期判断年龄函数,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-07-16
- 下面小编就为大家带来一篇C语言实现时间戳转日期的算法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-04-25
- 这篇文章主要为大家详细介绍了微信小程序实现根据日期和时间排序功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-08-26
- 公司电脑各式各样的都有,里面的设置也有很多不统一的,我们做软件一般会从系统中获取一些数据,比如日期时间,环境变量的路径参数,可以用批处理文件达到我们所想要的目的,也可以用C#代码...2020-06-25
- JavaScript获取当前日期时间同时显示星期几,具体代码如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="/jquery/1.7.0/jquery.min.js...2015-10-23
- php教程 strtotime()计算今天与指定日期之天数 $date1 = strtotime('2011-04-30'); //把日期转换成时间戳 $date2 = time(); //取当前时间的时间戳 $nowtime=strftime...2016-11-25
- 下面小编就为大家带来一篇浅析GridView中显示时间日期格式的问题。小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2021-09-22