i have this function with inputs $c(folder name) and $shownum(# of pics to show)
it ouputs a defined number of pics in the specified directy. the pics are named as follows: there are many but these are a few for an example
sample_pic_0_01.jpg
sample_pic_0_02.jpg
sample_pic_1_01.jpg
sample_pic_1_02.jpg
.....
...
..
i need to output these pics with one more parameter, the first number character after the letters. so basically i think i would would need to count back 8 spaces from the right and set that character as a variable like so
sample_pic_$var_01.jpg
the names of the pics will not always be the same but that number character will always be 8 char from the right.
conceptually i need the output of the function to go from
showScreens('../content/'.$dir.'/screens',$shownum);
to
showScreens('../content/'.$dir.'/screens/...$var..',$shownum);
ive tried everything with no success, any pointers would be appreciated. this is the working original code, all my failed attempts are not in this this is clean code just need to add on thanks for you time
<?php
$cwd = $_SERVER['REQUEST_URI'];
$cwd = substr($cwd, 0, strrpos($cwd, '/' + 1));
function showScreens($c,$shownum) {
$d = opendir($c);
$counter=1;
while($f = readdir($d)) {
if(strpos($f, '.') === 0) continue;
$ff = $c . '/' . $f;
$ext=substr($f,-3,3);
if ($ext=='jpg'){
$counter++;
}
}
echo "number of jpgs $counter<br>showing $shownum<br>directory: $c<br>";
$mod=round($counter/$shownum);
$counter=1;
$d = opendir($c);
while($f = readdir($d)) {
if(strpos($f, '.') === 0) continue;
$ff = $c . '/' . $f;
$ext=substr($f,-3,3);
if ($ext=='jpg' && $counter%$mod==0){
//echo('<li><img src="' . $cwd . $ff . '">' . $ff . '</li>');
//echo $counter;
echo('<img width=150 src="' . $cwd . $ff . '">');
}
$counter++;
//recursive
//if(is_dir($ff)) paintUndersideOfFox($ff);
}
echo('</ul>');
}
if (!isset($shownum)){
$shownum=10;
}
if (!isset($dir)){
die();
}
showScreens('../content/'.$dir.'/screens',$shownum);
?>