Skip to content

Instantly share code, notes, and snippets.

@madfriend
Created April 17, 2013 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madfriend/5407374 to your computer and use it in GitHub Desktop.
Save madfriend/5407374 to your computer and use it in GitHub Desktop.
preg_match_all + callbacks = preg_match_callback. No support for flags though.
<?php
function preg_match_callback($expression, $subject, $callback) {
static $matches_count = 0;
preg_replace_callback($expression, function($matches) use($callback) {
call_user_func($callback, $matches);
}, $subject, -1, $matches_count);
return $matches_count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment