I have some code that will randomly load an image from an array, but I want to tweak it to be able to randomly choose a php file and "include()" it in my page.
Here's the original code:
And here's my tweaked version that gave me an error:
I'm pretty new to php, so any help is greatly appreciated. Thanks in advance!
Here's the original code:
Code:
<?php
$file_array = array
('http://www.samplesite.com/images/image1.jpg',
'http://www.samplesite.com/images/image2.jpg',
'http://www.samplesite.com/images/image3.jpg',
'http://www.samplesite.com/images/image4.jpg',
'http://www.samplesite.com/images/image5.jpg');
$total = count($file_array);
$random = (mt_rand()%$total);
$file = "$file_array[$random]";
print("<img src=$file></a>");
?>
Code:
<?php
$file_array = array
('http://www.samplesite.com/samplefile1.php',
'http://www.samplesite.com/samplefile2.php',
'http://www.samplesite.com/samplefile3.php',
'http://www.samplesite.com/samplefile4.php',
'http://www.samplesite.com/samplefile5.php');
$total = count($file_array);
$random = (mt_rand()%$total);
$file = "$file_array[$random]";
include('$file');
?>
Comment