当前位置: 编程技术>php
本页文章导读:
▪PHP日期处理的小例子 mysql按日期、时间查询的例子 1,php处理日期的例子
代码示例:
<?php
//php日期处理
date_default_timezone_set('PRC'); //默认时区
echo "今天:",date("Y-m-d",time()),"<br>";
echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>";.........
▪PHP+Ajax实时自动检测是否联网的实现代码 本节主要内容:
PHP+Ajax结合,实现实时自动检测是否联网。
1,html代码
代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ht.........
▪php程序执行显示进度条的实例代码 本节主要内容:
学习php中进度条的实现方法。
1,php代码
代码示例:
<?php
session_start();
$zs=21;//设置任务总数
if(!isset()($_SESSION['num']))
$_SESSION['num']=$zs;//赋予session变量值
$jd=$.........
[1]PHP日期处理的小例子 mysql按日期、时间查询的例子
来源: 互联网 发布时间: 2013-12-24
1,php处理日期的例子
代码示例:
<?php
//php日期处理
date_default_timezone_set('PRC'); //默认时区
echo "今天:",date("Y-m-d",time()),"<br>";
echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>";
echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>";
echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>";
echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>"; //www.
echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>";
echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>";
echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>";
echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>";
echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>";
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";
//php日期处理
date_default_timezone_set('PRC'); //默认时区
echo "今天:",date("Y-m-d",time()),"<br>";
echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>";
echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>";
echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>";
echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>"; //www.
echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>";
echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>";
echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>";
echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>";
echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>";
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";
2,mysql日期操作,按日期、时间查询
代码示例:
#mysql查询今天、昨天、7天、近30天、本月、上一月 数据
#今天
select * from 表名 where to_days(时间字段名) = to_days(now());
#昨天
SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) – TO_DAYS( 时间字段名) <= 1
#7天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名)
#近30天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名)
#本月
SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, ‘%Y%m’ ) = DATE_FORMAT( CURDATE( ) , ‘%Y%m’ )
#上一月
SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , ‘%Y%m’ ) , date_format( 时间字段名, ‘%Y%m’ ) ) =1
#今天
select * from 表名 where to_days(时间字段名) = to_days(now());
#昨天
SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) – TO_DAYS( 时间字段名) <= 1
#7天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(时间字段名)
#近30天
SELECT * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(时间字段名)
#本月
SELECT * FROM 表名 WHERE DATE_FORMAT( 时间字段名, ‘%Y%m’ ) = DATE_FORMAT( CURDATE( ) , ‘%Y%m’ )
#上一月
SELECT * FROM 表名 WHERE PERIOD_DIFF( date_format( now( ) , ‘%Y%m’ ) , date_format( 时间字段名, ‘%Y%m’ ) ) =1
[2]PHP+Ajax实时自动检测是否联网的实现代码
来源: 互联网 发布时间: 2013-12-24
本节主要内容:
PHP+Ajax结合,实现实时自动检测是否联网。
1,html代码
代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP+Ajax实时自动检测是否联网-www.</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
<!--
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function start(){
createXMLHttpRequest();
var url="getNetLink";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
}
function callback(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
document.getElementById("shownetlink").innerHTML = xmlHttp.responseText;
setTimeout("start()",8000);
}
}
}
// -->
</script>
</head>
<body onload="start();">
<h1>PHP+Ajax实时自动检测是否联网</h1>
<p>当前网络状态:<span id="shownetlink"></span></p>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP+Ajax实时自动检测是否联网-www.</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
<!--
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function start(){
createXMLHttpRequest();
var url="getNetLink";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
}
function callback(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
document.getElementById("shownetlink").innerHTML = xmlHttp.responseText;
setTimeout("start()",8000);
}
}
}
// -->
</script>
</head>
<body onload="start();">
<h1>PHP+Ajax实时自动检测是否联网</h1>
<p>当前网络状态:<span id="shownetlink"></span></p>
</body>
</html>
2,php代码
代码示例:
<?php
//检测网络连接,是否已联网
public function getNetLink(){
header("cache-control:no-cache,must-revalidate");
header("Content-Type:text/html;charset=utf-8");
$file=fopen("http://www./", "r");
if (!$file){
$shownetlink = "<font color=\"red\">网络连接失败</font>";
}else{
$shownetlink = "<font color=\"#06C\">网络连接正常</font>";
}
echo $shownetlink;
}
//检测网络连接,是否已联网
public function getNetLink(){
header("cache-control:no-cache,must-revalidate");
header("Content-Type:text/html;charset=utf-8");
$file=fopen("http://www./", "r");
if (!$file){
$shownetlink = "<font color=\"red\">网络连接失败</font>";
}else{
$shownetlink = "<font color=\"#06C\">网络连接正常</font>";
}
echo $shownetlink;
}
[3]php程序执行显示进度条的实例代码
来源: 互联网 发布时间: 2013-12-24
本节主要内容:
学习php中进度条的实现方法。
1,php代码
代码示例:
<?php
session_start();
$zs=21;//设置任务总数
if(!isset()($_SESSION['num']))
$_SESSION['num']=$zs;//赋予session变量值
$jd=$_SESSION['num']--;//进度值
echo $jd;//显示进度值
echo "<br />";
echo 100-round($jd/$zs*100)."%";//显示完成进度百分比
?>
session_start();
$zs=21;//设置任务总数
if(!isset()($_SESSION['num']))
$_SESSION['num']=$zs;//赋予session变量值
$jd=$_SESSION['num']--;//进度值
echo $jd;//显示进度值
echo "<br />";
echo 100-round($jd/$zs*100)."%";//显示完成进度百分比
?>
2,图形化的进度条演示示例。
代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>进度条demo--www.</title>
<script type="text/javascript" language="javascript" src="/js/jquery-1.9.1.min.js"></script>
<script language="javascript" type="text/javascript">
////判断窗体是否最大化
//if (window.screen) {//判断浏览器是否支持window.screen判断浏览器是否支持screen
//var myw = screen.availWidth; //定义一个myw,接受到当前全屏的宽
//var myh = screen.availHeight; //定义一个myw,接受到当前全屏的高
//window.moveTo(0, 0); //把window放在左上脚
//window.resizeTo(myw, myh); //把当前窗体的长宽跳转为myw和myh
//}
//弹出隐藏层
function ShowDiv(show_div, bg_div) {
document.getElementById(show_div).style.display = 'block';
document.getElementById(bg_div).style.display = 'block';
var bgdiv = document.getElementById(bg_div);
bgdiv.style.width = document.body.scrollWidth;
$("#" + bg_div).height($(document).height());
};
//关闭弹出层
function CloseDiv(show_div, bg_div) {
document.getElementById(show_div).style.display = 'none';
document.getElementById(bg_div).style.display = 'none';
$("#country").val($("#name").val());
};
//窗口大小改变时
$(window).resize(function() {
if (!$('#MyDiv').is(':hidden')) popup();
});
//重新设置遮罩层的高和宽
function popup() {
var maskHeight = $(document).height();
var maskWidth = $(window).width();
$('#fade').css({ height: maskHeight, width: maskWidth }).show();
}
</script>
<style type="text/css">
.black_overlay { display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.5; opacity: 0.5; filter: alpha(opacity=50); -khtml-opacity: 0.5; }
.white_content { display: block; position: absolute; top: 45%; left: 40%; width: 18%; height: 6%; z-index: 1002; overflow: visible; color: #FFF; }
<!--
.white_content_small { display: block; position: fixed; top: 20%; left: 30%; width: 40%; height: 50%; border: 16px solid lightblue; background-color: white; z-index: 1002; overflow: auto; }
-->
#MyDiv .text { text-align: center; }
#jdtbj { background-color: #ACACAC; height: 13px; width: 208px; }
#bfb { height:13px; display:block; text-align:center; font-size:11px; color:#333; width:208px; position: absolute; top: 17px; }
#jdt { height:13px; display:block; text-align:center; font-size:11px; color:#333; background-image: url(/blog_article/loadings.gif); width:<?php echo 100-round($jd/$zs*100)."%";?>; }
</style>
</head>
<body>
<h1>欢迎访问:<a href="http://www." target="_blank">http://www.</a></h1>
<div id="fade" ></div>
<div id="MyDiv" >
<div >正在载入中......</div>
<div id="jdtbj">
<div id="bfb"><?php echo 100-round($jd/$zs*100)."%";?></div>
<div id="jdt"></div>
<h1>欢迎访问:<a href="http://www." target="_blank">http://www.</a></h1>
</div>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>进度条demo--www.</title>
<script type="text/javascript" language="javascript" src="/js/jquery-1.9.1.min.js"></script>
<script language="javascript" type="text/javascript">
////判断窗体是否最大化
//if (window.screen) {//判断浏览器是否支持window.screen判断浏览器是否支持screen
//var myw = screen.availWidth; //定义一个myw,接受到当前全屏的宽
//var myh = screen.availHeight; //定义一个myw,接受到当前全屏的高
//window.moveTo(0, 0); //把window放在左上脚
//window.resizeTo(myw, myh); //把当前窗体的长宽跳转为myw和myh
//}
//弹出隐藏层
function ShowDiv(show_div, bg_div) {
document.getElementById(show_div).style.display = 'block';
document.getElementById(bg_div).style.display = 'block';
var bgdiv = document.getElementById(bg_div);
bgdiv.style.width = document.body.scrollWidth;
$("#" + bg_div).height($(document).height());
};
//关闭弹出层
function CloseDiv(show_div, bg_div) {
document.getElementById(show_div).style.display = 'none';
document.getElementById(bg_div).style.display = 'none';
$("#country").val($("#name").val());
};
//窗口大小改变时
$(window).resize(function() {
if (!$('#MyDiv').is(':hidden')) popup();
});
//重新设置遮罩层的高和宽
function popup() {
var maskHeight = $(document).height();
var maskWidth = $(window).width();
$('#fade').css({ height: maskHeight, width: maskWidth }).show();
}
</script>
<style type="text/css">
.black_overlay { display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: black; z-index: 1001; -moz-opacity: 0.5; opacity: 0.5; filter: alpha(opacity=50); -khtml-opacity: 0.5; }
.white_content { display: block; position: absolute; top: 45%; left: 40%; width: 18%; height: 6%; z-index: 1002; overflow: visible; color: #FFF; }
<!--
.white_content_small { display: block; position: fixed; top: 20%; left: 30%; width: 40%; height: 50%; border: 16px solid lightblue; background-color: white; z-index: 1002; overflow: auto; }
-->
#MyDiv .text { text-align: center; }
#jdtbj { background-color: #ACACAC; height: 13px; width: 208px; }
#bfb { height:13px; display:block; text-align:center; font-size:11px; color:#333; width:208px; position: absolute; top: 17px; }
#jdt { height:13px; display:block; text-align:center; font-size:11px; color:#333; background-image: url(/blog_article/loadings.gif); width:<?php echo 100-round($jd/$zs*100)."%";?>; }
</style>
</head>
<body>
<h1>欢迎访问:<a href="http://www." target="_blank">http://www.</a></h1>
<div id="fade" ></div>
<div id="MyDiv" >
<div >正在载入中......</div>
<div id="jdtbj">
<div id="bfb"><?php echo 100-round($jd/$zs*100)."%";?></div>
<div id="jdt"></div>
<h1>欢迎访问:<a href="http://www." target="_blank">http://www.</a></h1>
</div>
</div>
</body>
</html>
最新技术文章: