you can use the pregreplace syntax to do that...
PHP Code:
<?php
// This is taken from somewhere and written in PHP
$str = 'Hello, [name]
This is my phone number [phone]-[number]';
// Those are the variables to be replaced with inside []
$name = 'Mike';
$phone = '+39';
$number = '555...';
$msg = preg_replace("/\[(\w+)\]/e", "\$\\1", $str);
print $msg;
?>