Voting

: max(eight, one)?
(Example: nine)

The Note You're Voting On

development at HashNotAdam dot com
12 years ago
From PHP 5.3 you can use an anonymous function to pass local variables into the callback.

<?php

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'];
}
?>

<< Back to user notes page

To Top