Calling function in this way
$message = preg_replace_callback('#\[img\]([1-3])\[/img\]#isU', 'replaceLink', $message);
is ok. And should work.
But I see that in your function replaceLink()
function replaceLink($matches){
$final = '<img src=\''.$path[$matches[1]].'\' alt=\''.$data['alt'].'\'/>';
return $final;
}
you use variables which are not defined in that frunction $path
, $data
.
If they are defined outside the function and they are not global then they will be null inside replaceLink()
and you should get error.
Try to use this code
$message = preg_replace_callback(
'#\[img\]([1-3])\[/img\]#isU',
function($matches) use ($path, $data) {
$final = '<img src=\''.$path[$matches[1]].'\' alt=\''.$data['alt'].'\'/>';
return $final;
},
$message
);