本页文章导读:
▪php 随机显示图片的函数 本节主要内容:
介绍一个随机显示图片的php函数,多用于博客的展示窗、照片的随机展示等。
在看实例之前,为大家分享下php中生成随机数的几篇文章:
php生成随机数字和字母
php生成随机.........
▪php日历代码(附演示效果) 本节主要内容:
一个php实现的日历效果代码。
演示效果:
php日历源码,如下:
代码示例:
<?php
function build_calendar($month,$year,$dateArray) {
// 日历表头,星期天开始一直到星期六
$daysO.........
▪php日历代码分享 简单实用的php日历代码 php日历代码,简单实用的php日历代码。
例子:
代码示例:
<?php
header("content-type:text/html;charset=utf-8");
?>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<style>
fo.........
[1]php 随机显示图片的函数
来源: 互联网 发布时间: 2013-12-24
本节主要内容:
介绍一个随机显示图片的php函数,多用于博客的展示窗、照片的随机展示等。
在看实例之前,为大家分享下php中生成随机数的几篇文章:
php生成随机数字和字母
php生成随机密码的范例
php生成随机码的代码
用PHP生成随机数的函数
php生成随机数的例子
有了以上的基础,理解如下的php自定义函数,就不难了。
编辑推荐:php 随机显示图片的例子
例子:
代码示例:
<?php
/**
* 功能:随机显示图片
* Filename : img.php
* Usage:
* <img src=/blog_article/img.php>_br/index.html> * <img src=/blog_article/img/folder/images2/gt;_br/.html> * Edit: www.
**/
if($_GET['folder']){
$folder=$_GET['folder'];
}else{
$folder='/images/';
}
//存放图片文件的位置
$path = $_SERVER['DOCUMENT_ROOT']."/".$folder;
$files=array();
if ($handle=opendir("$path")) {
while(false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(substr($file,-3)=='gif' || substr($file,-3)=='jpg') $files[count($files)] = $file;
}
}
}
closedir($handle);
$random=rand(0,count($files)-1);
if(substr($files[$random],-3)=='gif') header("Content-type: image/gif");
elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg");
readfile("$path/$files[$random]");
?>
/**
* 功能:随机显示图片
* Filename : img.php
* Usage:
* <img src=/blog_article/img.php>_br/index.html> * <img src=/blog_article/img/folder/images2/gt;_br/.html> * Edit: www.
**/
if($_GET['folder']){
$folder=$_GET['folder'];
}else{
$folder='/images/';
}
//存放图片文件的位置
$path = $_SERVER['DOCUMENT_ROOT']."/".$folder;
$files=array();
if ($handle=opendir("$path")) {
while(false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(substr($file,-3)=='gif' || substr($file,-3)=='jpg') $files[count($files)] = $file;
}
}
}
closedir($handle);
$random=rand(0,count($files)-1);
if(substr($files[$random],-3)=='gif') header("Content-type: image/gif");
elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg");
readfile("$path/$files[$random]");
?>
[2]php日历代码(附演示效果)
来源: 互联网 发布时间: 2013-12-24
本节主要内容:
一个php实现的日历效果代码。
演示效果:
php日历源码,如下:
代码示例:
<?php
function build_calendar($month,$year,$dateArray) {
// 日历表头,星期天开始一直到星期六
$daysOfWeek = array('S','M','T','W','T','F','S');
// 本月第一天的位置
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
// 获取本月天数
$numberDays = date('t',$firstDayOfMonth);
// 获取本月第一天
$dateComponents = getdate($firstDayOfMonth);
// 获取月份的英文单词
$monthName = $dateComponents['month'];
$dayOfWeek = $dateComponents['wday'];
// 月历表头
$calendar = "<table >";
$calendar .= "<caption>$monthName $year</caption>";
$calendar .= "<tr>";
// 星期表头
foreach($daysOfWeek as $day) {
$calendar .= "<th >$day</th>";
}
// 开始输出日历
// 初始化天数计数器,从1号开始
$currentDay = 1;
$calendar .= "</tr><tr>";
// 使用变量 $dayOfWeek 可以保证一周七天精确输出
if ($dayOfWeek > 0) {
$calendar .= "<td colspan='$dayOfWeek'> </td>";
}
$month = str_pad($month, 2, "0", STR_PAD_LEFT);
while ($currentDay <= $numberDays) {
// 7天一行,7天一到新增一行
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);
$date = "$year-$month-$currentDayRel";
$calendar .= "<td rel='$date'>$currentDay</td>";
// 计数器
$currentDay++;
$dayOfWeek++;
}
// 最后一行表格的处理,往往最后一行不可能全部填满,需要要空格填充。
if ($dayOfWeek != 7) {
$remainingDays = 7 - $dayOfWeek;
$calendar .= "<td colspan='$remainingDays'> </td>";
}
$calendar .= "</tr>";
$calendar .= "</table>";
return $calendar;
}
?>
function build_calendar($month,$year,$dateArray) {
// 日历表头,星期天开始一直到星期六
$daysOfWeek = array('S','M','T','W','T','F','S');
// 本月第一天的位置
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
// 获取本月天数
$numberDays = date('t',$firstDayOfMonth);
// 获取本月第一天
$dateComponents = getdate($firstDayOfMonth);
// 获取月份的英文单词
$monthName = $dateComponents['month'];
$dayOfWeek = $dateComponents['wday'];
// 月历表头
$calendar = "<table >";
$calendar .= "<caption>$monthName $year</caption>";
$calendar .= "<tr>";
// 星期表头
foreach($daysOfWeek as $day) {
$calendar .= "<th >$day</th>";
}
// 开始输出日历
// 初始化天数计数器,从1号开始
$currentDay = 1;
$calendar .= "</tr><tr>";
// 使用变量 $dayOfWeek 可以保证一周七天精确输出
if ($dayOfWeek > 0) {
$calendar .= "<td colspan='$dayOfWeek'> </td>";
}
$month = str_pad($month, 2, "0", STR_PAD_LEFT);
while ($currentDay <= $numberDays) {
// 7天一行,7天一到新增一行
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
$calendar .= "</tr><tr>";
}
$currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);
$date = "$year-$month-$currentDayRel";
$calendar .= "<td rel='$date'>$currentDay</td>";
// 计数器
$currentDay++;
$dayOfWeek++;
}
// 最后一行表格的处理,往往最后一行不可能全部填满,需要要空格填充。
if ($dayOfWeek != 7) {
$remainingDays = 7 - $dayOfWeek;
$calendar .= "<td colspan='$remainingDays'> </td>";
}
$calendar .= "</tr>";
$calendar .= "</table>";
return $calendar;
}
?>
php日历代码的调用示例:
代码示例:
<?php
//php日历
$dateComponents = getdate();
$month = $dateComponents['mon'];
$year = $dateComponents['year'];
echo build_calendar($month,$year,$dateArray);
?>
//php日历
$dateComponents = getdate();
$month = $dateComponents['mon'];
$year = $dateComponents['year'];
echo build_calendar($month,$year,$dateArray);
?>
[3]php日历代码分享 简单实用的php日历代码
来源: 互联网 发布时间: 2013-12-24
php日历代码,简单实用的php日历代码。
例子:
代码示例:
<?php
header("content-type:text/html;charset=utf-8");
?>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<style>
form{
margin:0px;
padding:0px;
}
td{
text-align:center;
width:80px;
}
</style>
<?php
/**
* 简单实用的php日历代码
* edit: www.
*/
if(!emptyempty($_GET)){
$year = $_GET['year'];
$month = $_GET['month'];
}
if(emptyempty($year)){
$year = date('Y');
}
if(emptyempty($month)){
$month = date('m');
}
$start_weekday = date('w',mktime(0,0,0,$month,1,$year));
//echo $start_weekday;
$days = date('t',mktime(0,0,0,$month,1,$year));
//echo $days;
$week = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
$i = 0;
$k = 1;
$j = 0;
echo '<table border = "1">';
echo '<tr><td colspan = 7 style = "text-align:center">'.$year.'年'.$month.'月'.'</td></tr>';
echo '<tr>';
for($i = 0;$i < 7;$i++){
echo '<td>'.$week[$i].'</td>';
}
echo '</tr>';
echo '<tr>';
for($j = 0;$j < $start_weekday;$j++){
echo '<td >'.$j.'</td>';
}
while($k <= $days){
if($k == date('d')){
echo '<td >'.$k.'</td>';
}else{
echo '<td>'.$k.'</td>';
}
if(($j+1) % 7 == 0){
echo '</tr><tr>';
}
$j++;
$k++;
}
while($j % 7 != 0){
echo '<td >'.$j.'</td>';
$j++;
}
echo '</tr>';
echo '<tr>';
echo "<td><a href=/blog_article/.html".lastYear($year,$month).">".'<<'.'</a></td>';
echo "<td><a href=/blog_article/.html".lastMonth($year,$month).">".'<'.'</a></td>';
echo '<td colspan = 3 style = "text-align:center">';
echo '<form name = "myform" method = "GET">';
echo '<select name = year >';
for($start_year = 1970;$start_year<2039;$start_year++){
echo '<option value ='. $start_year.'>'.$start_year.'</option>';
}
echo '</select>'.'年';
echo '<select name = month>';
for($start_month = 1;$start_month<=12;$start_month++){
echo '<option value = '.$start_month.'>'.$start_month.'</option>';
}
echo '</select>';
echo '月';
echo '<input type = "submit" name = "search" value = "查询">';
echo '</form>';
echo '</td>';
echo "<td><a href=/blog_article/.html".nextYear($year,$month).">".'>>'.'</a></td>';
echo "<td><a href=/blog_article/.html".nextMonth($year,$month).">".'>'.'</a></td>';
echo '</tr>';
echo '</table>';
function lastYear($year,$month){
$year = $year-1;
return "year=$year&month=$month";
}
function lastMonth($year,$month){
if($month == 1){
$year = $year -1;
$month = 12;
}else{
$month--;
}
return "year=$year&month=$month";
}
function nextYear($year,$month){
$year = $year+1;
return "year=$year&month=$month";
}
function nextMonth($year,$month){
if($month == 12){
$year = $year +1;
$month = 1;
}else {
$month++;
}
return "year=$year&month=$month";
}
?>
header("content-type:text/html;charset=utf-8");
?>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<style>
form{
margin:0px;
padding:0px;
}
td{
text-align:center;
width:80px;
}
</style>
<?php
/**
* 简单实用的php日历代码
* edit: www.
*/
if(!emptyempty($_GET)){
$year = $_GET['year'];
$month = $_GET['month'];
}
if(emptyempty($year)){
$year = date('Y');
}
if(emptyempty($month)){
$month = date('m');
}
$start_weekday = date('w',mktime(0,0,0,$month,1,$year));
//echo $start_weekday;
$days = date('t',mktime(0,0,0,$month,1,$year));
//echo $days;
$week = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
$i = 0;
$k = 1;
$j = 0;
echo '<table border = "1">';
echo '<tr><td colspan = 7 style = "text-align:center">'.$year.'年'.$month.'月'.'</td></tr>';
echo '<tr>';
for($i = 0;$i < 7;$i++){
echo '<td>'.$week[$i].'</td>';
}
echo '</tr>';
echo '<tr>';
for($j = 0;$j < $start_weekday;$j++){
echo '<td >'.$j.'</td>';
}
while($k <= $days){
if($k == date('d')){
echo '<td >'.$k.'</td>';
}else{
echo '<td>'.$k.'</td>';
}
if(($j+1) % 7 == 0){
echo '</tr><tr>';
}
$j++;
$k++;
}
while($j % 7 != 0){
echo '<td >'.$j.'</td>';
$j++;
}
echo '</tr>';
echo '<tr>';
echo "<td><a href=/blog_article/.html".lastYear($year,$month).">".'<<'.'</a></td>';
echo "<td><a href=/blog_article/.html".lastMonth($year,$month).">".'<'.'</a></td>';
echo '<td colspan = 3 style = "text-align:center">';
echo '<form name = "myform" method = "GET">';
echo '<select name = year >';
for($start_year = 1970;$start_year<2039;$start_year++){
echo '<option value ='. $start_year.'>'.$start_year.'</option>';
}
echo '</select>'.'年';
echo '<select name = month>';
for($start_month = 1;$start_month<=12;$start_month++){
echo '<option value = '.$start_month.'>'.$start_month.'</option>';
}
echo '</select>';
echo '月';
echo '<input type = "submit" name = "search" value = "查询">';
echo '</form>';
echo '</td>';
echo "<td><a href=/blog_article/.html".nextYear($year,$month).">".'>>'.'</a></td>';
echo "<td><a href=/blog_article/.html".nextMonth($year,$month).">".'>'.'</a></td>';
echo '</tr>';
echo '</table>';
function lastYear($year,$month){
$year = $year-1;
return "year=$year&month=$month";
}
function lastMonth($year,$month){
if($month == 1){
$year = $year -1;
$month = 12;
}else{
$month--;
}
return "year=$year&month=$month";
}
function nextYear($year,$month){
$year = $year+1;
return "year=$year&month=$month";
}
function nextMonth($year,$month){
if($month == 12){
$year = $year +1;
$month = 1;
}else {
$month++;
}
return "year=$year&month=$month";
}
?>
最新技术文章: