substr_count()

Counts the number of substring occurrences
php program

function searchtext ($haystack, $needle){
if (substr_count ($haystack, $needle) == 0){
echo "No instances were found of this search query";
} else {
$startpos = 0;
$lookagain = true;
while ($lookagain){
if ($pos = strpos ($haystack, $needle, $startpos)){
echo "The search term \"$needle\" was found at position: $pos ";
$startpos = $pos + 1;
} else {
$lookagain = false;
}
}
echo "Your search for \"$needle\" within \"$haystack\" returned a total of \"" . substr_count ($haystack, $needle) . "\" matches.";
}
}
searchtext ("Hello World!","o");
o/p..........


More

Comments