hi, random image php script <?php $imgpath = "img"; $handle = opendir( "$imgpath" ); $imgArray = array(); while($file = readdir($handle)) { if( $file != "." && $file != ".." ) { array_push( $imgArray, $file ); } } closedir( $handle ); mt_srand( (double)microtime( ) * 1000000 ); $randval = mt_rand( 0, sizeof( $imgArray ) - 1 ); print( "<IMG SRC=\"$imgpath/" . $imgArray[ $randval ] . "\">" ); ?> Code (markup): How to add text(not random) to every random image example: pic1.jpg here is text for image 1 pic2.jpg here is text for image 2 etc when random image is pic1.jpg, it must always be "here is text for image 1" Is it possible to make a txt files with names pic1.txt, pic2.txt ....etc and when pic1.jpg appear to show and pic1.txt ? any help is welcome
This should work: <?php $text = array(); $file = file_get_contents("text.txt"); $lines = explode("\n", $file); foreach ($lines as $line){ $splitLine = explode(";", $line); $text[$splitLine[0]] = $splitLine[1]; } ?> Code (markup): example of text.txt: pic1.jpg;text for pic1 pic2.jpg;text for pic2 pic3.jpg;text for pic3 Code (markup): Usage: echo $text[$randval];