pneudralics Posted September 11, 2009 Share Posted September 11, 2009 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"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/173916-solved-how-to-i-save-a-while-loop-into-a-string/ Share on other sites More sharing options...
mikesta707 Posted September 11, 2009 Share Posted September 11, 2009 if you want to display whats inside imagesubject2 outside the loop then echo it outside the loop.... I dont understand your question here Quote Link to comment https://forums.phpfreaks.com/topic/173916-solved-how-to-i-save-a-while-loop-into-a-string/#findComment-916812 Share on other sites More sharing options...
pneudralics Posted September 11, 2009 Author Share Posted September 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/173916-solved-how-to-i-save-a-while-loop-into-a-string/#findComment-916815 Share on other sites More sharing options...
mikesta707 Posted September 11, 2009 Share Posted September 11, 2009 $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 Quote Link to comment https://forums.phpfreaks.com/topic/173916-solved-how-to-i-save-a-while-loop-into-a-string/#findComment-916816 Share on other sites More sharing options...
pneudralics Posted September 11, 2009 Author Share Posted September 11, 2009 Thanks for the help. Looks like an array. Don't use them that much so I wasn't to familiar with it. Quote Link to comment https://forums.phpfreaks.com/topic/173916-solved-how-to-i-save-a-while-loop-into-a-string/#findComment-916825 Share on other sites More sharing options...
mikesta707 Posted September 11, 2009 Share Posted September 11, 2009 yep its an array. You could, technically, concatenate all the stuff into one big string, but the array method is much cleaner in my opinion Quote Link to comment https://forums.phpfreaks.com/topic/173916-solved-how-to-i-save-a-while-loop-into-a-string/#findComment-916826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.