Hi,
Optimizing the str_replace()
The
str_replace() function in PHP can be slow, due it’s duplication of data even if no replacement is being performed.
PHP Code:
$src_str = file_get_contents("CONTENT_FILE_PATH");
$src = array('abc', 123, 'text');
$dst = array('cba', 321, 'txet');
// eliminate unnecessary replacement attempts
foreach ($src as $k => $v)
if (strpos($src_str, $src) === FALSE)
unset($src[$k], $dst[$k]);
if ($src) $new_str = str_replace($src, $dst, $src_str);
Click to view the difference of strtr() and str_replace() Thanks,
R.Gopi