I used str_replace in output buffering in order to translate a website. It works perfectly on local server and test server, but totally fails in production server.
Here is the original code :
function lang_modify($buffer){
require('get_messages.php');
foreach($messages as $message){
$stringToBeReplaced = $message[0];
$stringReplace = $message[1];
$buffer = str_replace($stringToBeReplaced,$stringReplace, $buffer);
}
return $buffer;
}
$lang = $_SESSION['lang'];
if($lang=='en'){
$buffer = ob_start('lang_modify');
}
Then, as I am translating japanese characters to english, I thought about a multibyte problem, so I replaced the str_replace with mb_ereg_replace. Again, it was working nice on local server and test server, but not on production server.
function lang_modify($buffer){
require('get_messages.php');
mb_regex_encoding("UTF-8");
foreach($messages as $message){
$pattern = "(".$message[0].")";
$stringReplace = $message[1];
$buffer = mb_ereg_replace($pattern, $stringReplace, $buffer);
}
return $buffer;
}
In both cases, unexpected strings are being modified causing error in javascript files, and in most of cases expected replacement are not replaced. Is there any chance that the str_replace is depending to the server settings ?
I precise that I can't use another way to translate the website. I have to make this working on the production server.
Do anyone have a clue about how to fix this ?