$words = array("stripos", "click", "substr", "save", "search", "sizeof");
$count = array(0, 0, 0, 0, 0, 0);
$file = "d:\\url.php";
$fhandle = fopen($file, "r");
if ($fhandle)
{
while ( ($line = fgets($fhandle)) !== false)
{
for ($i = 0, $s = $line; $i < 6; $i++, $s = $line)
while ( ($pos = strpos($s, $words[$i])) != false )
{
$s = substr($s, $pos + strlen($words[$i]));
$count[$i]++;
}
}
}
fclose($fhandle);
for ($i = 0; $i < 6; $i++)
printf("The word: %s appear %3d times in file: %s\n
", $words[$i], $count[$i], $file);
/*
run:
The word: stripos appear 5 times in file: d:\url.php
The word: click appear 50 times in file: d:\url.php
The word: substr appear 14 times in file: d:\url.php
The word: save appear 4 times in file: d:\url.php
The word: search appear 7 times in file: d:\url.php
The word: sizeof appear 2 times in file: d:\url.php
*/