MattLG Posted March 30, 2009 Share Posted March 30, 2009 I have a callback to a function which is expecting two parameters: function productsMenu($page, $match) {......} The callback is stored in $callback which needs to be called from $page (which is an instance of a Page object). So I need to send "$this" to the callback, along with one of the matches. Something like this: $content = preg_replace("/()()().../e", $callback($this, $2), $content); (you get the idea...) But, I've tried all kinds of syntax with various combinations of quotes, doublequotes, backslashes, ampersands. Everything that I thought should work, didn't work, and nothing that I just guessed worked either. Any help or pointers you can give are very gratefully received. Many thanks MattLG Link to comment https://forums.phpfreaks.com/topic/151836-sending-multiple-parameters-to-a-callback-in-preg_replace-or-preg_replace_callba/ Share on other sites More sharing options...
corbin Posted March 30, 2009 Share Posted March 30, 2009 Try: $content = preg_replace("/()()().../e", "$callback" . "($this, '\2')", $content); (That assumes \2 will never contain a single quote.) Link to comment https://forums.phpfreaks.com/topic/151836-sending-multiple-parameters-to-a-callback-in-preg_replace-or-preg_replace_callba/#findComment-797314 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.