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
https://forums.phpfreaks.com/topic/120898-image-and-text/
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
https://forums.phpfreaks.com/topic/120898-image-and-text/#findComment-623223
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
https://forums.phpfreaks.com/topic/120898-image-and-text/#findComment-623253
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.