If you only want to replace strings, then drop the regular expression functions! (a 
common mistake)

Use for example str_replace, or in this case, strtr which is better because it accepts 
an array as replacement pattern.

For example: 
  $foo = array("foo" => "apple", "bar" => "banana");
  $string = "I like foos and bars";
  $string = strtr($string, $foo);
  echo $string;

output:
  I like apples and bananas

// Victor

----- Original Message ----- 
From: "'Nick Wilson'" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, January 12, 2002 1:17 PM
Subject: Re: [PHP] multiple replaces...


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> 
> * On 12-01-02 at 13:02
> * Lauri Vain said....
> 
> > Hi Nick,
> >
> > Yes, I thought about that. But, what should I do when the markers are absolutely 
>NOT in any sequence.
> >
> > I also thought about something like
> > $replace[1][1] = "!one!"; //marker
> > $replace[1][2] = "hehee"; //replace with
> > $replace[1][1] = "test"; //marker
> > $replace[1][2] = "foobar"; //replace with
> > $replace[1][1] = "repl"; //marker
> > $replace[1][2] = "humpty-dumpty"; //replace with
> > $replace[1][1] = "blah"; //marker
> > $replace[1][2] = "boo"; //replace with
> >
> > Now, when I would do a loop thingie that goes through all those, then it would be 
>a pretty nice and compact solution...
> >
> > What about speed issues regarding this solution?
> 
> I don't think speed will be an issue unless you have thousands of
> markers, in which case you'll need to re-think the whole thing.
> 
> Can you not put all of your markers in an array like
> 
> $markers=array("m1", "m2", "m_whatever");
> 
> and all your replacements likewise
> 
> $replace=array("r1", "r2", "r_whatever");
> 
> and then loop through like that?
> 
> If not, explain a little more about the context of the problem and let's
> see if we can come up with an alternative.
> - --
> 
> Nick Wilson
> 
> Tel: +45 3325 0688
> Fax: +45 3325 0677
> Web: www.explodingnet.com
> 
> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
> 
> iD8DBQE8QCk+HpvrrTa6L5oRAozIAJ4opVPFNwawBmQNIAHLZN/gdCt+lgCeLgmC
> 5hurUMezrXCg3cVtYgieGGE=
> =xRPE
> -----END PGP SIGNATURE-----
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to