Wednesday, 15 August 2012

php - Find all the occurrence points of a letter within a string -



php - Find all the occurrence points of a letter within a string -

i have next code:

<?php $word = "aeagle"; $letter = "e"; $array = strposall($aegle, $letter); print_r($array); function strposall($haystack, $needle) { $occurrence_points = array(); $pos = strpos($haystack, $needle); if ($pos !== false) { array_push($occurrence_points, $pos); } while ($pos = strpos($haystack, $needle, $pos + 1)) { array_push($occurrence_points, $pos); } homecoming $occurrence_points; } ?>

as in example, if have aegle word , i'm searching e within it, function should homecoming array values 1 , 4 in it.

what's wrong code?

i think you're passing wrong parameters, shouild $word instead of $aegle

php arrays string search

No comments:

Post a Comment