PHP transforms the random greeting every day, the PHP transform greeting
In this paper, we explain how to automatically change the random greeting daily by PHP. Share to everyone for your reference. The specific analysis is as follows:
Here pre-defined a PHP array, which contains some random greeting, the call is specified by day, month or year to automatically change the greeting, if the month is selected, will be a monthly replacement greeting display, do not have to manually replace each month, and this PHP code than the use of JS implementation of the search engine-friendly
function Randomquotebyinterval ($TimeBase, $QuotesArray) { //Make sure it is a integer $TimeBase = Intval ($ Timebase); How many items is in the array? $ItemCount = count ($QuotesArray); By using the modulus operator we get a pseudo //random index position that's between zero and the //maximal Value (ItemCount) $RandomIndexPos = ($TimeBase% $ItemCount); Now return the random array element return $QuotesArray [$RandomIndexPos];} /***--See the example sections below for a** detailed instruction.*/
Examples of Use:
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//to date (' H '); Quote changes every hour//to 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);
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/998572.html www.bkjia.com true http://www.bkjia.com/PHPjc/998572.html techarticle PHP Implementation of the daily automatic conversion of random greetings, PHP transform Greetings This article describes the PHP implementation of the automatic daily change of the random greeting language method. Share to everyone for your reference. ...