I have a code where it runs fine on phpFiddle.org, but when I tried to run it on my web server, it displayed an internal web error for some reason. I'm wondering what I did wrong. Thanks.
$text = "cheese\'s bacon cats ";
$replacement = ["cheese\'s" => "bacon", "bacon" => "apple", "cats" => "dogs"];
$search = array_map(function($v){
return preg_quote($v, "/");
}, array_keys($replacement));
echo $text = preg_replace_callback("/\b(" . implode("|", $search) . ")\b/", function($m)use($replacement){
return $replacement[$m[1]];
}, $text);
P.S: My web server is ipage.com
Here's the edited version of the code:
$text = "apple\'s bacon cats ";
$replacement = array("apple\'s" => "bacon", "bacon" => "apple", "cats" => "dogs");
$search = array_map(function($v){
return preg_quote($v, "/");
}, array_keys($replacement));
echo $text = preg_replace_callback("/\b(" . implode("|", $search) . ")\b/", function($m)use($replacement){
return $replacement[$m[1]];
}, $text);