To use variable from the parent scope of the anonymous callback function passed to preg_replace_callback(), utilize the use() parameter.
$var1 = "one";
$var2 = "two";
$line = preg_replace_callback('/^.*$/',
function( $matches ) use ( $var1, $var2 ) {
return( $var1 . " " . $var2 );
}, $line);
Will replace the entire string with the concatenated values or $var1 and $var2 ("one two") from the parent scope.