You are here: Re: tricky replace function « PHP Programming Language « IT news, forums, messages
Re: tricky replace function

Posted by Darko on 11/09/07 00:06

On Nov 8, 11:13 pm, windandwaves <nfranc...@gmail.com> wrote:
> On Nov 7, 10:21 am, Michael Fesser <neti...@gmx.de> wrote:
>
>
>
> > .oO(windandwaves)
>
> > >Why is this so hard?
>
> > >I can do a str_replace. That is easy. However, I do many of them AND
> > >I want to make sure that one replacement does not override another...
>
> > >e.g.
> > >statement 1 could be: replace "cats" with "dogs"
> > >statement 2 could be: replaced "do" with "did"
>
> > >as you can see, this could turn "cats" into "didgs"
>
> > >That is what is the hard part.
>
> > That's why I suggested to give strtr() a try, which should avoid this
> > problem.
>
> > Micha
>
> Hi Micha
>
> >From what I understand strtr only replace characters, not sentences,
>
> so I am not sure if that would work.
>
> Cheers
>
> Nicolaas

Please read the manual more carefully. Because, yes, the first few
lines say the following:

> This function returns a copy of str, translating all occurrences of each
> character in from to the corresponding character in to.

What also says there is the following:
> strtr() may be called with only two arguments. If called with two arguments it
> behaves in a new way: from then has to be an array that contains string -> string
> pairs that will be replaced in the source string.

> strtr() will always look for the longest possible match first and will *NOT* try
> to replace stuff that it has already worked on.

Cheers

 

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

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