假设我有类似 b<a=2<sub>2</sub> && d>c = 4<sub>2</sub> == 6<sub>3</sub>
"<子>"字重复3次。如何将所有 3 个位置放入数组中?子>
尝试如下:
$find = 'b<a=2<sub>2</sub> && d>c = 4<sub>2</sub> == 6<sub>3</sub>';
function strpos_all($haystack, $needle) {
$offset = 0;
$allpos = array();
while (($pos = strpos($haystack, $needle, $offset)) !== FALSE) {
$offset = $pos + strlen($needle);
$allpos[] = $pos;
}
return $allpos;
}
print_r(strpos_all($find, "<sub>"));