replaceOneByOne($msg, $match, $replace)); } public static function replaceOneByOne($string, $fromList, $toList) { $offset = 0; foreach ($fromList as $index => $item) { $position = strpos($string, $item, $offset); if ($position !== false) { $left = substr($string, 0, $position); $right = substr($string, $position + strlen($item)); $middle = $toList[$index]; $string = $left . $middle . $right; $offset = strlen($left . $middle); } } return $string; } }