|
Posted by jmark on 08/13/07 15:04
On Aug 13, 2:44 am, gosha bine <stereof...@gmail.com> wrote:
> On 12.08.2007 21:45 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"?
>
> what you probably want is strtr
>
> $repl = array('a' => 'apple', 'p' => 'pear');
> $text = 'a p';
> echo strtr($text, $repl);
>
> --
> gosha bine
>
> makrell ~http://www.tagarga.com/blok/makrell
> php done right ;)http://code.google.com/p/pihipi- Hide quoted text -
>
> - Show quoted text -
Thanks for showing me this function. I like it
[Back to original message]
|