Skip to content

Instantly share code, notes, and snippets.

@gbradley
Last active December 19, 2015 00:09
Show Gist options
  • Select an option

  • Save gbradley/5866826 to your computer and use it in GitHub Desktop.

Select an option

Save gbradley/5866826 to your computer and use it in GitHub Desktop.
Emulate preg_match_all with multibyte support for PHP <6
function _mb_ereg_search_all($str, $re, $resultOrder = 0){
// 0 mimics PREG_PATTERN_ORDER
// 1 mimics PREG_SET_ORDER
$matches = Array();
mb_ereg_search_init($str, $re);
while (($m = mb_ereg_search_regs())){
$matches[] = $m;
}
if ($resultOrder == 0){
$patternMatches = array_fill(0, count($matches), Array());
foreach ($matches as $i => $match){
foreach ($match as $j => $submatch){
$patternMatches[$j][] = $submatch;
}
}
$matches = $patternMatches;
}
return $matches;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment