note 60628 deleted from function.str-replace by bjori
| From: | bjori@php.net | Date: | Sun, 26 Mar 2006 22:20:02 +0000 |
| Subject: | note 60628 deleted from function.str-replace by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106664@lists.php.net to get a copy of this message | ||
Note Submitter: vlatko dot surlan at RMVMEgmail dot com
----
Note the unfortunate consequence of beeing unable to format str_replace like this:
<?php
pairs = array(
'this' => 'to this',
'this one' => 'to this one',
/* many lines here */
);
str_replace(pairs, context);
?>
The correct form requires two arrays with no visual support for the code reader that would help him
to match the actual replacement pairs in a natural and visually seamless manner. In this aspect the
code above is by far more maintainable and rugged.
The simple solution is as follows:
<?php
pairs = array(
'this' => 'to this',
'this one' => 'to this one',
/* many lines here */
);
str_replace(array_keys(pairs), array_values(pairs), context);
?>
Note that the overhead brought by creating two new arrays for purely aesthetic reasons might be a
waste of perfectly good CPU time.