str_replace() with associative array

Posted by Qiao on Stack Overflow See other posts from Stack Overflow or by Qiao
Published on 2010-03-08T04:28:23Z Indexed on 2010/03/08 4:51 UTC
Read the original article Hit count: 290

Filed under:

You can use arrays with str_replace():

$array_from = array ('from1', 'from2'); 
$array_to = array ('to1', 'to2');

$text = str_replace ($array_from, $array_to, $text);

But what if you have associative array?

$array_from_to = array (
 'from1' => 'to1';
 'from2' => 'to2';
);

How can you use it with str_replace()?
Speed matters - array is big enough.

© Stack Overflow or respective owner

Related posts about php