Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <div id="home-slogan">
  2.  
  3. <?php
  4.  
  5. $filename = "testimonials/testimonial.txt"; #specify file
  6. $file = fopen($filename, "r"); #open file
  7. $numLines = count(file($filename)); #count number of lines
  8. $lines = file($filename); #read lines into array
  9. $randomTestimonial = rand(0,$numLines); #generate random number
  10. ?>
  11.  
  12. <h1 id="heading" align="center">"<?php echo $lines[$randomTestimonial];?>"</h1>
  13. <button type="button" id="next">Next Testimonial</button>
  14.  
  15. <script>
  16.  
  17. var randomTestimonial = <?php echo $lines[$randomTestimonial];?>;
  18.  
  19. $("#next").click(function(){
  20. $("#heading").replaceWith(randomTestimonial);
  21. });
  22.  
  23. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement