Php conditionals to echo proper audio tags


/ Published in: HTML
Save to your folder(s)

Php conditionals to echo proper audio tags


Copy this code and paste it in your HTML
  1. <?php
  2. $time = date(G); // Get the hour of day
  3.  
  4.  
  5. // Match the hour of the day to the proper track and set to autoplay and loop
  6. if ($time == 0) {
  7. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/12-am.mp3' /></audio>";
  8. }elseif ($time == 1) {
  9. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/1-am.mp3' /></audio>";
  10. } elseif ($time == 2) {
  11. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/2-am.mp3' /></audio>";
  12. } elseif ($time == 3) {
  13. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/3-am.mp3' /></audio>";
  14. } elseif ($time == 4) {
  15. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/4-am.mp3' /></audio>";
  16. } elseif ($time == 5) {
  17. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/5-am.mp3' /></audio>";
  18. } elseif ($time == 6) {
  19. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/6-am.mp3' /></audio>";
  20. } elseif ($time == 7) {
  21. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/7-am.mp3' /></audio>";
  22. } elseif ($time == 8) {
  23. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/8-am.mp3' /></audio>";
  24. } elseif ($time == 9) {
  25. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/9-am.mp3' /></audio>";
  26. } elseif ($time == 10) {
  27. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/10-am.mp3' /></audio>";
  28. } elseif ($time == 11) {
  29. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/11-am.mp3' /></audio>";
  30. } elseif ($time == 12) {
  31. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/12-pm.mp3' /></audio>";
  32. } elseif ($time == 13) {
  33. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/1-pm.mp3' /></audio>";
  34. } elseif ($time == 14) {
  35. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/2-pm.mp3' /></audio>";
  36. } elseif ($time == 15) {
  37. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/3-pm.mp3' /></audio>";
  38. } elseif ($time == 16) {
  39. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/4-pm.mp3' /></audio>";
  40. } elseif ($time == 17) {
  41. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/5-pm.mp3' /></audio>";
  42. } elseif ($time == 18) {
  43. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/6-pm.mp3' /></audio>";
  44. } elseif ($time == 19) {
  45. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/7-pm.mp3' /></audio>";
  46. } elseif ($time == 20) {
  47. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/8-pm.mp3' /></audio>";
  48. } elseif ($time == 21) {
  49. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/9-pm.mp3' /></audio>";
  50. } elseif ($time == 22) {
  51. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/10-pm.mp3' /></audio>";
  52. } elseif ($time == 23) {
  53. echo "<audio id='audio_1' controls preload autoplay='autoplay' loop><source src='music/11-pm.mp3' /></audio>";
  54. } // end if
  55. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.