The problem is that each iteration of the $conversion
loop replaces the last instance of the $final_message
variable. One solution would be to name the initial variable this way:
$final_message = $this->request->data['Minichat']['message'];
And then feed that variable back thru each time in the loop:
foreach ($conversion as $k=>$v) {
$final_message = preg_replace('/'.$k.'/',$v,$final_message);
}
$final_message = nl2br($final_message);