Last active
December 19, 2015 00:09
-
-
Save gbradley/5866826 to your computer and use it in GitHub Desktop.
Emulate preg_match_all with multibyte support for PHP <6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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