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

Posted by jmark on 08/12/07 22:25

On Aug 12, 3:37 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> jm...@fastermail.com wrote:
> > I saw this example in php.net
>
> > // Outputs: apearpearle pear
> > $letters = array('a', 'p');
> > $fruit = array('apple', 'pear');
> > $text = 'a p';
> > $output = str_replace($letters, $fruit, $text);
> > echo $output;
>
> > and I am bit puzzled why the output is the way it is instead of
>
> > apple pear
>
> > it looks like str_replace is replacing the p in apple to pear but why
> > does not replace the p in pear to pear and the a to apple and why is
> > the output not "apple pear"?
>
> > Thanks
> > John
>
> John,
>
> I haven't looked at the source code, but I would expect it does would be
> effectively the same as:
>
> $output = str_replace('a', 'apple', 'a p');
> $output = str_replace('p', 'pear', '$output);
>
> Which produces the same output.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -

Yes, that sounds reasonable as to how it is working.
I had thought that str_replace replaces all elements in the array at
the same time. I think this would have been a more intuitive approach

Thanks
John

 

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

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