PHP transforms the random greeting automatically every day, php transform greeting _php Tutorial

Source: Internet
Author: User

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. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.