<?php
$text="Welcome to PHP";
$searchchar="e";
$count="0"; //zero
$searchchar="e";
$count="0"; //zero
for($i="0"; $i<strlen($text); $i=$i+1){
if(substr($text,$i,1)==$searchchar){
$count=$count+1;
}
if(substr($text,$i,1)==$searchchar){
$count=$count+1;
}
}
echo $count
?>
This will count how many times the character "e" occurs in that text (Welcome to PHP).
0 comments:
Post a Comment