ozestretch Posted June 17, 2009 Share Posted June 17, 2009 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 Link to comment https://forums.phpfreaks.com/topic/162514-solved-read-txt-file-looping-each-line-exploding-by-deliminator/ Share on other sites More sharing options...
xphoid Posted June 17, 2009 Share Posted June 17, 2009 Have you tried printing out $line to see if the full line is even there? Also you could try using file() instead of fopen()/fgets(). Link to comment https://forums.phpfreaks.com/topic/162514-solved-read-txt-file-looping-each-line-exploding-by-deliminator/#findComment-857758 Share on other sites More sharing options...
ozestretch Posted June 17, 2009 Author Share Posted June 17, 2009 $line echos nothing :-\ This is really the only way I know/thought I knew to do it. Any ideas? Link to comment https://forums.phpfreaks.com/topic/162514-solved-read-txt-file-looping-each-line-exploding-by-deliminator/#findComment-857797 Share on other sites More sharing options...
ozestretch Posted June 17, 2009 Author Share Posted June 17, 2009 wrong $description[$file][0]; right $description[$file]; ozestrech $foo = 'noob'; $ozestretch = $foo; echo $ozestretch Link to comment https://forums.phpfreaks.com/topic/162514-solved-read-txt-file-looping-each-line-exploding-by-deliminator/#findComment-857853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.