|
Posted by Confused but working on it on 09/14/07 21:34
On 2007-09-13 07:37:21 -0700, "Steve" <no.one@example.com> said:
>
> "Confused but working on it" <PostInGroups@wherever.com> wrote in
> message news:2007091209500416807-PostInGroups@wherevercom...
>> Just wanted to say thanks for the posts helping me make ths work. Added
>> a few comments and after the readdir used a pattern match to test for
>> .jpg, and seems to work fine on my test setup. Maybe I should test for
>> gif, tiff, and png... Anyway, here's the code:
>> <?php
>> //Open images directory
>> $dir = opendir("images");
>> //read files in the dir
>> while (($file = readdir($dir)) !== false)
>> //test to make sure jpg
>> if (eregi("\.jpg",$file))
>
> one suggestion,
>
> why are you using ereg? beside the fact that it is vastly more resource
> intensive than preg and slower, neither is needed because substr is
> faster than both.
>
> while ...
> $extension = strtolower(substr($file, -4));
> if ($extension != '.jpg'){ continue; }
> whatever you want to do with the jpg from here
> end
>
> you could also use fnmatch to pattern match for file names. you could
> even use glob()...
>
> $directory = 'images';
> $extension = '*.jpg';
> chdir($directory);
> foreach (glob($extension) as $image)
> {
> echo '<img src="' . $directory . '/' . $image . '" class="pad1em">';
> }
>
> i personally prefer glob() for such things since it requires less code
> to get what you want.
>
> anyway...there's always more than one way to skin a cat. ;^)
Hey Steve,
I'm using eregi because I found a line on a site or in the manual that
didn't get .jpg so I fixed it to get the jpgs. Not a programmer, and
barely even a hobbyist so I do what I can to kludge some stuff
together. Maybe I can read preg, substr and glob and use one of them
but was pretty happy with the cat being skinned at all. :)
Basically I'm just writing a paragraph about and event and putting
160px images on the page with a bit of padding. Today I was going to
make this thing read thumbs and link to images... Might have to take a
nap.
Thanks for the help
Navigation:
[Reply to this message]
|