Nếu các bạn có nhu cầu tìm tất cả vị trí xuất hiện của chuỗi $needle trong chuỗi $haystack trong PHP thì ngay bên dưới đây hàm strpos_all sẽ giúp bạn thực hiện đều này!
function strpos_all($haystack, $needle) {
$offset = 0;
$allpos = array();
while (($pos = strpos($haystack, $needle, $offset)) !== FALSE) {
$offset = $pos + 1;
$allpos[] = $pos;
}
return $allpos;
}
Hy vọng hữu ích với bạn!
Nosomovo