foreach and str_replace
am 16.09.2007 23:36:49 von Confused but working on it
So I've been trying to get a bit of code to:
Read all of the files in a dir called thumbs, but not the . and .., use
the filename in a link to get the same filename in an images dir. Now
I'm trying to use a foreach and glob as suggested, and get rid of the
part of the string that has the dir info. SO the below produces all my
thumbs nicely and all are links.
foreach (glob("thumbs/*.jpg") as $file)
{
str_replace('thumbs/', '', $file);
echo "";
}
?>
But why doesn't the sring manipulatioon not work? I'm very grateful for
the line with the str_replace. If i remove the braces above i get the
last thumb and a bad link. Replace braces and I get all my thumbs. But
the link still has thumbs/ in it.
hmmm.
thx..ron
Re: foreach and str_replace
am 16.09.2007 23:58:31 von luiheidsgoeroe
On Sun, 16 Sep 2007 23:36:49 +0200, Confused but working on it =
wrote:
> So I've been trying to get a bit of code to:
> Read all of the files in a dir called thumbs, but not the . and .., us=
e =
> the filename in a link to get the same filename in an images dir. Now =
=
> I'm trying to use a foreach and glob as suggested, and get rid of the =
=
> part of the string that has the dir info. SO the below produces all my=
=
> thumbs nicely and all are links.
>
>
> foreach (glob("thumbs/*.jpg") as $file)
> {
> str_replace('thumbs/', '', $file);
This does NOT alter $file. $file is not taken as a reference and altered=
=
inside str_replace();
$file =3D str_replace('thumbs/', '', $file);
> echo "
\">";
> }
> ?>
>
> But why doesn't the sring manipulatioon not work? I'm very grateful fo=
r =
> the line with the str_replace. If i remove the braces above i get the =
=
> last thumb and a bad link. Replace braces and I get all my thumbs. But=
=
> the link still has thumbs/ in it.
>
> hmmm.
>
> thx..ron
Why do your images live in a thumbs dir and you still want an '/images/'=
=
link?
However, this may help you:
foreach (glob("thumbs/*.jpg") as $file){
$filename =3D basename($file);
echo "
class=3D'pad1em'>";
}
?>
-- =
Rik Wasmus
Re: foreach and str_replace
am 16.09.2007 23:58:48 von zeldorblat
On Sep 16, 5:36 pm, Confused but working on it
wrote:
> So I've been trying to get a bit of code to:
> Read all of the files in a dir called thumbs, but not the . and .., use
> the filename in a link to get the same filename in an images dir. Now
> I'm trying to use a foreach and glob as suggested, and get rid of the
> part of the string that has the dir info. SO the below produces all my
> thumbs nicely and all are links.
>
>
> foreach (glob("thumbs/*.jpg") as $file)
> {
> str_replace('thumbs/', '', $file);
> echo "";
> }
> ?>
>
> But why doesn't the sring manipulatioon not work? I'm very grateful for
> the line with the str_replace. If i remove the braces above i get the
> last thumb and a bad link. Replace braces and I get all my thumbs. But
> the link still has thumbs/ in it.
>
> hmmm.
>
> thx..ron
You're not doing anything with the return value of str_replace().
I think you want:
$file = str_replace('thumbs/', '', $file);
Re: foreach and str_replace
am 17.09.2007 00:10:37 von Confused but working on it
On 2007-09-16 14:58:48 -0700, ZeldorBlat said:
> On Sep 16, 5:36 pm, Confused but working on it
> wrote:
>> So I've been trying to get a bit of code to:
>> Read all of the files in a dir called thumbs, but not the . and .., use
>> the filename in a link to get the same filename in an images dir. Now
>> I'm trying to use a foreach and glob as suggested, and get rid of the
>> part of the string that has the dir info. SO the below produces all my
>> thumbs nicely and all are links.
>>
>>
>> foreach (glob("thumbs/*.jpg") as $file)
>> {
>> str_replace('thumbs/', '', $file);
>> echo "";
>> }
>> ?>
>>
>> But why doesn't the sring manipulatioon not work? I'm very grateful for
>> the line with the str_replace. If i remove the braces above i get the
>> last thumb and a bad link. Replace braces and I get all my thumbs. But
>> the link still has thumbs/ in it.
>>
>> hmmm.
>>
>> thx..ron
>
> You're not doing anything with the return value of str_replace().
>
> I think you want:
>
> $file = str_replace('thumbs/', '', $file);
I do dumb things like that. :)
thx..ron
Re: foreach and str_replace
am 17.09.2007 00:17:04 von Confused but working on it
On 2007-09-16 14:58:31 -0700, "Rik Wasmus" said:
>
> This does NOT alter $file. $file is not taken as a reference and altered
> inside str_replace();
>
> $file = str_replace('thumbs/', '', $file);
Yeah, that was dumb.
>> thx..ron
>
> Why do your images live in a thumbs dir and you still want an '/images/'
> link?
>
> However, this may help you:
>
>
> foreach (glob("thumbs/*.jpg") as $file){
> $filename = basename($file);
> echo "
> class='pad1em'>";
> }
> ?>
>
>
> --
> Rik Wasmus
My thumbs live in thumbs and the full size in images. Made sense to me.
I export from iPhoto a set of thumbs and then the larger pics.
foreach (glob("thumbs/*.jpg") as $file){
$filename = basename($file);
echo "
class='pad1em'>";
}
?>
Works great. I got those file markers and realized you took out the
"thumbs/" in the echo statement.
Uploaded and the files are in order of filename.
Next week maybe I'll learn how to take a directory named images and
create thumbs on the fly. Might hve been easier. :)
Thanks for all the help.
Ron