PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function strpos_recursive($haystack, $needle, $offset = 0, &$results = array()) { $offset = strpos($haystack, $needle, $offset); if($offset === false) { return $results; } else { $results[] = $offset; return strpos_recursive($haystack, $needle, ($offset + 1), $results); } } $string = 'This is some string'; $search = 'o'; $found = strpos_recursive($string, $search); if($found) { foreach($found as $pos) { echo 'Found "'.$search.'" in string "'.$string.'" at position <b>'.$pos.'</b><br />'; } } else { echo '"'.$search.'" not found in "'.$string.'"'; } ?>
Show:  
Copy Clear