Hi!
> function replace_spaces ($text) {
static $replacement = function ($matches) {
return str_replace ($matches[1], ' ', ' ').' ';
};
return preg_replace_callback ('/( +) /', $replacement, $text);
}
That is using static would result in creating the function only once.
I'm not sure this exactly one would work, as closure is not a constant
expression and thus its use as initializer may not work. However,
converting it to pseudo-singleton may work:
static $replacement = null;
if($replaceement == null) {
$replacement = function { blah-blah }
}
--
Stanislav Malyshev, Zend Software Architect
[EMAIL PROTECTED] http://www.zend.com/
(408)253-8829 MSN: [EMAIL PROTECTED]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php