基于 dulao 的答案的 'match_all' 辅助函数。有些人可能会发现它有用...
<?php
function mb_ereg_match_all($pattern, $subject, &$matches, $options = '', $setOrder = false, $offset = 0) {
if (!mb_ereg_search_init($subject, $pattern, $options)) {
return false;
}
if ($offset != 0 && !mb_ereg_search_setpos($offset)) {
return false;
}
$matches = [];
if (!mb_ereg_search()) {
return 0;
}
$regs = mb_ereg_search_getregs();
$count = 0;
do {
$count++;
if ($setOrder) {
foreach ($regs as $key => $val) {
$matches[$key][] = $val;
}
} else {
$matches[] = $regs;
}
$regs = mb_ereg_search_regs();
}
while($regs);
return $count;
}
?>