Jump to content

Help not echoing files with a certain letter them


tqla

Recommended Posts

Hello. I am using this code to look in a directory and echo out the contents:

 

<?php
$mydir = "images/home/";
$d = dir($mydir);
while($entry = $d->read()) {
if ($entry!= "." && $entry!= "..") {
echo "'" . $entry . "': { caption: '' }," ;
}
}
$d->close();
?>

 

In the folder are file names like 1.jpg, 1t.jpg, 2.jpg, 2t.jpg, 3.jpg, 3t.jpg, and so on.

 

I only wish to echo out the files that do NOT have a "t" in their name. Just 1.jpg, 2.jpg, 3.jpg and so on.

 

Can somebody show me how to add this? Thanks

Does all files that have a 't' in them always in this format [some number here]t.jpg? If they are then you can do this:

<?php
$mydir = "images/home/";
$d = dir($mydir);
while($entry = $d->read()) {
if ($entry!= "." && $entry != ".." && substr($entry, -4, 1) != 't') {
echo "'" . $entry . "': { caption: '' }," ;
}
}
$d->close();
?>

wildteen. thanks but I just tried your solution and the files with "t" still show up like this:

 

'1.jpg': { caption: '' },'10.jpg': { caption: '' },'10t.jpg': { caption: '' },'11.jpg': { caption: '' },'11t.jpg': { caption: '' },'12.jpg': { caption: '' }, and so on...

 

mrMarcus, yes "t" is for thumbnail. I was saving the seperate folder idea for if it can't be done through a bit a php code.

 

gerardcorr, where would I put the !strpos code? I tried it in the while loop and in the if statement but no go.

mrMarcus, yes "t" is for thumbnail. I was saving the seperate folder idea for if it can't be done through a bit a php code.

 

it can be done, yes, but in the future, normalization is the way to go to avoid headaches such as this.

 

if i were you, i'd take the time to make the changes now, but that's just me.

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.