First time here so apologies if I'm doing something wrong.
I have the following php code:
<?php
 $quoteFile = "quotes.txt";  //File holding qoutes
 $fp = fopen($quoteFile, "r");   //Opens file for read
 $content = fread($fp, filesize($quoteFile));
 $quotes = explode("\n",$content);   //Put quotes into array
 fclose($fp);   //Close the file
 srand((double)microtime()*1000000);  // randomize
 $index = (rand(1, sizeof($quotes)) - 1); //Pick random qoute
 ?>
The code fetches a random quote from a text file by randomly choosing one of the lines of the .txt file.
I then echo out the result using:
echo $quotes[$index];
However what I want to achieve and don't seem to be able to is to have a button (html) that when clicked executes the
echo $quotes[$index];to the current page. So that each time the button is clicked it prints/echo's out a random quote from the .text file.
I did mess about with just setting a button up to refresh the page which by default made a new random quote display but it sometimes just reloaded a blank so I'm hoping someone can help me achieve this better or prompt me in the right direction. Thank tou.
 
     
    