How do I use the values "returned" by preg_replace like in the following?
preg_replace($pattern, function('$1','$2'), $contents);
So it will pass the matches instead of $1 and $2 as strings ('$1' and '$2');
If function('$1','$2') really is a function call, then you cannot do it like that. It would be called before preg_replace is executed. In this case, you can use preg_replace_callback:
function foo($matches) {
// $matches[1] is $1
// $matches[2] is $2
}
preg_replace_callback($pattern, 'foo', $contents);
If it is not a function call, you have to explain better what you want to do.
$pattern = '/blabla/e'; //make sure to use the 'e' modifier
$result = preg_replace($pattern, "function('\\1', '\\2')", $contents);