Jump to content

Recommended Posts

I'm trying to save $imagesubject2 into it's own string outside of the while loop. I want to be able to display all the data from $imagesubject2 outside of the loop.

//List files
while ($item = readdir ($dp) ) {
if ( (is_file ($item)) AND (substr($item, 0, 1) != '.') ) {
//Get file size
$fs = filesize ($item);

//Get file modification date
$lm = date ('F j, Y' , filemtime($item));

	//Find image
	$imagepattern = '/^([0-9]){1,}.jpg$/';
	$imagesubject = "$item";

	if (preg_match($imagepattern, $imagesubject, $imagematches)) {
		//Open file
		$imagesubject2 = "$imagesubject";

	}
}
}

if you want to display whats inside imagesubject2 outside the loop then echo it outside the loop.... I dont understand your question here

 

I can't get it to echo everything outside the loop. It only echos 1 data and not all of them if I echo it outside the loop. So I'm thinking maybe if I can save it to a string inside the loop and echo the string outside it might work.

$imagesubject2 = array();
while ($item = readdir ($dp) ) {
   if ( (is_file ($item)) AND (substr($item, 0, 1) != '.') ) {
   //Get file size
   $fs = filesize ($item);
   
   //Get file modification date
   $lm = date ('F j, Y' , filemtime($item));

      //Find image
      $imagepattern = '/^([0-9]){1,}.jpg$/';
      $imagesubject = "$item";

      if (preg_match($imagepattern, $imagesubject, $imagematches)) {
         //Open file
         $imagesubject2[] = "$imagesubject";

      }
   }
}
$i = 0;
foreach($imagesubject2 as $sub){
echo "$i : $sub<br />";
$i++;
}

 

that should do the trick. if you want an explanation let me know

 

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.