Dan.W Posted May 28, 2007 Share Posted May 28, 2007 <?php $quotes = array( '<?php include "1.php"; ?>', '<?php require "2.php"; ?>', ); // generate a random number between zero // and the number of quotes -1 $rand = rand(0, (count($quotes)-1)); // output the random quote echo $quotes[$rand]; ?> I posted a similar thread earlier when I thought solved my problem, however I did not I cannot get this code (which generates a random entry from the quoted sections) to show ANY PHP, it will show HTML and Javascript, but not PHP. I have tried putting in variables to show each section when selected but then ALL the variables show once the script loads. It's seriously frustrating - been going at it for hours. Any help? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/53293-includerequire-within-an-array/ Share on other sites More sharing options...
trq Posted May 28, 2007 Share Posted May 28, 2007 <?php $quotes = range(1,2); $rand = rand(1, count($quotes)); include $quotes[$rand].'.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53293-includerequire-within-an-array/#findComment-263353 Share on other sites More sharing options...
Dan.W Posted May 28, 2007 Author Share Posted May 28, 2007 Thank you for the idea SOLUTION: <?php $quotes = array( '1', '2', ); // generate a random number between zero // and the number of quotes -1 $rand = rand(0, (count($quotes)-1)); // output the random quote include $quotes[$rand].'.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53293-includerequire-within-an-array/#findComment-263356 Share on other sites More sharing options...
trq Posted May 28, 2007 Share Posted May 28, 2007 Sorry, but your SOLUTION is flawed... use my code. Quote Link to comment https://forums.phpfreaks.com/topic/53293-includerequire-within-an-array/#findComment-263358 Share on other sites More sharing options...
Dan.W Posted May 29, 2007 Author Share Posted May 29, 2007 My SOLUTION works... Quote Link to comment https://forums.phpfreaks.com/topic/53293-includerequire-within-an-array/#findComment-263973 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.