php实现每天自动变换随机问候语的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php实现每天自动变换随机问候语的方法。分享给大家供大家参考。具体分析如下:

这里预先定义一个php数组,里面存放一些随机问候语,调用的时候指定是按照天,月还是年来自动更换问候语,如果选择月,则会每月更换一条问候语显示,不用每个月手动更换了,并且这段php代码比使用JS实现对搜索引擎友好

function RandomQuoteByInterval($TimeBase, $QuotesArray){
  // Make sure it is a integer
  $TimeBase = intval($TimeBase);
  // How many items are in the array?
  $ItemCount = count($QuotesArray);
  // By using the modulus operator we get a pseudo
  // random index position that is between zero and the
  // maximal value (ItemCount)
  $RandomIndexPos = ($TimeBase % $ItemCount);
  // Now return the random array element
  return $QuotesArray[$RandomIndexPos];
}
/*
** --> See the example section below for a
**   detailed instruction.
*/

使用范例:

// Use the day of the year to get a daily changing
// quote changing (z = 0 till 365)
$DayOfTheYear = date('z');
// You could also use:
// --> date('m'); // Quote changes every month
// --> date('h'); // Quote changes every hour
// --> date('i'); // Quote changes every minute
// Example array with some random quotes
$RandomQuotes = array(
  'No animals were harmed in the making of this snippet.',
  'Nice snippets',
  'The modulus operator rocks!',
  'PHP is cool.'
);
print RandomQuoteByInterval($DayOfTheYear, $RandomQuotes);

希望本文所述对大家的php程序设计有所帮助。

相关文章

简单采集了yahoo的一些数据

以前在公司就写过类似的东西,这次是帮以前的上司写了一个简单的采集程序。    很简单的。。汗。没什么技术含量的。    数据来源:http://c...

php弹出提示框的是实例写法

php中弹出对话框的方法如下,一般,在提交信息后需要弹出对话框提示,之后可以自动关闭对话框,弹出对话框有下面集中方法,其实都是利用javascript中的alert()方法。提示结束后关...

PHP+Javascript实现在线拍照功能实例

本文实例讲述了PHP+Javascript实现在线拍照功能。分享给大家供大家参考。具体如下: 我们在一些WEB应用中可能会遇到这样的情况,用户需要自己现场拍照并上传到会员系统。比如驾校采...

php反射学习之依赖注入示例

本文实例讲述了php反射学习之依赖注入。分享给大家供大家参考,具体如下: 先看代码: <?php if (PHP_SAPI != 'cli') { exit('Pl...

PHP面向对象程序设计内置标准类,普通数据类型转为对象类型示例

本文实例讲述了PHP面向对象程序设计内置标准类,普通数据类型转为对象类型。分享给大家供大家参考,具体如下: 内置标准类 PHP中,有很多“现成的类”,其中有一个被称为“内置标准类”。这个...