- preg_replace_callback: documentation ( source)
<?php
$text = "This is a text with some@email.com an e-mail address in it";
echo preg_replace_callback(
'~[\w.-]+@(?:[\w-]+\.)+\w+~',
function($m) {
return "**{$m[0]}**";
},
$text
);