I need really short script that will work this way; I want to add 5 names and after 24h it will display another name ( every day another name ). Example, if I will add: Name1 Name2 Name3 and day1 it will show name1, after 24h(day2) it will show Name2 and after another 24h it will show Name3 Thanks a lot !
something like <?php if(date("D") == "Mon"){ echo "name1"; }elseif(date("D") == "Tue"){ echo "name2"; }elseif(date("D") == "Wed"){ echo "name3"; } //and so on until Sun ?> Code (markup): should do
TheFileThatChosesTheName.php <? $name_file = file("names.txt"); $last_name_position = file("temp.txt"); //If today (the 15th) is not the same as yesterday or last time script was //loaded print the next name in the list in the file names.txt if (date("j") != $last_name_position[1]) { //----------This should prevent errors about array out of bounds----------// //If the following produces errors change the -1 to 0 //If it is still producing errors remove this section if ($new_position => count($name_file)) { $fp = fopen($last_name_position, 'w'); fwrite($fp, "-1".' '.date("j")); fclose($fp); } $last_name_position = file("temp.txt"); //-------The above should prevent errors about array out of bounds-------// //Set today's name position $new_position = $last_name_position[0] +1; //Write to file today's new name position and the current date (the 15th) $fp = fopen($last_name_position, 'w'); fwrite($fp, $new_position.' '.date("j")); fclose($fp); //Print the name to screen echo($name_file[$new_position]); } ?> PHP: names.txt name1 name2 name3 name4 name5 ... Code (markup): temp.txt 0 15 Code (markup): The zero in the temp.txt file means the beginning of the list. Please note where the new lines are, Very Important. Or something similar to the above... It will not assign a certain name to a certain day as yoes_san's code does. This code will go through the entire names.txt file, each time the file is called or loaded it will print the next name in the list. Please note I haven't tested the code but I think it should work.