You are here: Re: foreach and str_replace « PHP Programming Language « IT news, forums, messages
Re: foreach and str_replace

Posted by ZeldorBlat on 09/16/07 21:58

On Sep 16, 5:36 pm, Confused but working on it
<PostInGro...@wherever.com> 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.
>
> <?php
> foreach (glob("thumbs/*.jpg") as $file)
> {
> str_replace('thumbs/', '', $file);
> echo "<a href='images/$file'><img src='$file' class=\"pad1em\"></a>";
> }
> ?>
>
> 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);

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация