Jump to content

[SOLVED] Read .txt file looping each line exploding by deliminator


ozestretch

Recommended Posts

I have a text file which contains lines, each line contains information separated by comma

 

eg:

myimage.jpg,My Image Description

anotherimage.jpg,And another description here

..... so on

 

I am using the below code to match the first variable (the image name) to the actual image located on server and return its description.

 

??? ??? It seems to do all of it fine, except it is only returning the first character of the description  ??? ???

 

 

$images = "gallery/"; # Location of images
$text   = "gallery.txt";

$fh=@fopen($text, "r");

while(!feof($fh))
{
  $line=fgets($fh);
  $temp = explode(",", $line);
  $description[$temp[0]] = $temp[1];
  unset($temp);
}

if ($handle = opendir($images)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && $file != rtrim($images,"/")) {
           $files[] = $file;
       }
   }
   closedir($handle);
}

 

And to display the description I call for

foreach($files as $file)
{

  echo '<img src="' . $images . $file .'" /><br />' . $description[$file][0];

}

 

Any ideas are welcomed, thanks

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.