Boxerman Posted August 22, 2008 Share Posted August 22, 2008 Hi guys, my question is, is there a way to display a image if a curtain text is typed? so like: "Hello" when that is said a picture that i upload to my webroot called hello.jpeg or something will be displayed next to the text? i use a random quote system, and i want to add it in that? but how? Thanks P.S this is my random quotes code <? $quoteFile = "shows.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 echo $quotes[$index]; //Print quote to screen ?> Quote Link to comment Share on other sites More sharing options...
Boxerman Posted August 22, 2008 Author Share Posted August 22, 2008 just thinking about it, i fort can i do quote numbers? like [1] means quote 1 [2] qoute 2 etc... and in the php script have it so if [1] is displayed show the picture in [1] which will contain image url or something? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 22, 2008 Share Posted August 22, 2008 $quoteFile = "shows.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 $id = array_rand($quotes); $myQuote = $quotes[$id]; $imagesDir = '/images/quotes/'; if(file_exists($imagesDir.$myQuote.'jpg')){ echo '<p><img src="'.$imagesDir.$myQuote.'jpg" alt="'.$myQuote.'" /></p>'; echo '<p>'.$myQuote.'</p>'; }else{ echo '<p>'.$myQuote.'</p>'; echo '<p>Quote has no image</p>'; } Quote Link to comment Share on other sites More sharing options...
Boxerman Posted August 22, 2008 Author Share Posted August 22, 2008 how do assign a qoute id in the shows.txt then? as thats just lines like Boxerman cool etc.. and i want a different image for each one? thanks! you are a big help! Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 22, 2008 Share Posted August 22, 2008 how do assign a qoute id in the shows.txt then? as thats just lines like Boxerman cool etc.. and i want a different image for each one? thanks! you are a big help! huh??? Quote Link to comment Share on other sites More sharing options...
Boxerman Posted August 22, 2008 Author Share Posted August 22, 2008 Right sorry to confuse you in my show.txt is this Boxermans Summer Hits DJ K On The Decks Live! Nightmares Rock Hour DJ Duxs Liverpool Invadsion nothing else jsut them on ech new line how would i assign a picture to each one? a different picture Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 22, 2008 Share Posted August 22, 2008 Give this a try, I modified you Text File. Line 1 is the directory of your images (with trailing slash) all the lines after are your quotes, followed by 3 semi-colons then the image name. New Text file: /dir/to/your/images/ Boxermans Summer Hits;;;mypic1.jpg DJ K On The Decks Live!;;;mypic2.jpg Nightmares Rock Hour;;;mypic3.jpg DJ Duxs Liverpool Invadsion ;;;mypic4.jpg New PHP: $quoteFile = "shows.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 $id = array_rand($quotes); while($id != 0){ $id = array_rand($quotes); } $myQuoteLine = $quotes[$id]; list($myQuote,$myImg) = explode(';;;',$myQuoteLine); echo '<p>Quote: '.$myQuote.'</p>'; echo '<p>Image: '.$quotes[0].$myImg.'</p>'; Quote Link to comment Share on other sites More sharing options...
Boxerman Posted August 22, 2008 Author Share Posted August 22, 2008 this is the outcome http://radio101.co.uk/testfolder/random.php Quote Link to comment 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.