Read the documentation here, http://www.php.net/manual/en/function.preg-replace-callback.php
Here is an example of preg_replace_callback
$source = preg_replace_callback('/&#(\d+);/m', function($matches){
return utf8_encode(chr($matches[1]));
}, $source);