1

What I'm trying to do is to have PHP read a txt file, and put it into an array, with each line of the txt file being an individual element (each line of the txt file hold a url). After doing this, I would like for the array to be randomly organised, so that when a html button is pushed, a randomly selected url from the array is outputted into a new tab. This is the code I have so far:

            <?php
            $urls = file_get_contents('txtfilehere'), FILE_IGNORE_NEW_LINES);
            $random = $urls[mt_random(0, count($urls) - 1)];    
            ?>
         <script type="text/javascript">
            function randsite($urls){
                window.location = $urls;
            }
            </script>
            <h5> &rarr;  <button id="randsite"> PLEASE! </button> &larr; </h5>
        

Any help would be greatly appreciated.

  • 2
    One issue, your PHP doesn't actually echo the text out after it runs, so the JS can't get to it. – Russ J Sep 22 '20 at 01:50
  • You seem to be mixing up what PHP and JS respectively do. [Start here.](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Jeto Sep 22 '20 at 03:06

0 Answers0