I know this has been asked elsewhere, but I can't find the precise situation (and understand it!) so I'm hoping someone might be able to help with code here.
There's an array of changes to be made. Simplified it's:
$title = "Tom's wife is called Tomasina";
$change_to = array(
"Tom" => "Fred",
"wife" => "girlfriend",
);
$title = preg_replace_callback('(\w+)', function( $match )use( $change_to ) {
return $array[$match[1]];
}, $title);
I'm hoping to get back "Fred's girlfriend is called Tomasina" but I'm getting all sorts of stuff back depending on how I tweak the code - none of which works!
I'm pretty certain I'm missing something blindingly obvious so I apologise if I can't see it!
Thank you!