preg_replace_callback does not return values

0

My code is not returning the $owner and $mid values in the make_user() function Why?

preg_replace_callback('/(^|[^a-z0-9_])M([a-z0-9_]+)/i', function($matches, $owner, $mid) {
    return $this->mark_user($matches, $owner, $mid);
}, $text);
    
asked by anonymous 10.07.2014 / 15:41

1 answer

1

Example of the function (Since the user did not post the entire context of the question):

public function replace_variables( $subject, $otherVars ) { 
$linkPatterns = array( 
    '/(<a .*)href=(")([^"]*)"([^>]*)>/U', 
    "/(<a .*)href=(')([^']*)'([^>]*)>/U" 
); 

$callback = function( $matches ) use ( $otherVars ) { 
    $this->replace_callback($matches, $otherVars); 
}; 

return preg_replace_callback($this->patterns, $callback, $subject); 
}

public function replace_callback($matches, $otherVars) { 
    return $matches[1] . $otherVars['myVar']; 
} 

source: link

    
10.07.2014 / 17:03