$callback = function($matches) { return jakas_funkcja($matches[1]); }; return preg_replace_callback($wzorzec, $callback, /*wejscie*/);