Jump to content

Image and text


Boxerman

Recommended Posts

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
?>

Link to comment
Share on other sites

$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>';
}

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.