English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

If i want to know how many of the word "table" was repeated in a file called "file1.txt", how do i do that?(PHP)

2006-07-04 00:44:10 · 4 answers · asked by frewatg 1 in Computers & Internet Programming & Design

4 answers

$count = 0;
$string = "table";
$file = explode (" ", file_get_contents ('file1.txt') );
foreach ( $str in $file )
{
if($str == $string)
{
$count++;
}
}
echo $string." found ".$count." times";
?>

2006-07-04 00:56:54 · answer #1 · answered by programmer 4 · 0 0

open up the file in word. when the document is open, hit "ctrl" + F on the keyboard. type "table" in the text field, then click "find next" and count how many times it is found.

2006-07-04 07:49:42 · answer #2 · answered by Brian W 5 · 0 0

$count = 0;
$string = "table";
$file = explode (" ", file_get_contents ('file1.txt') );
foreach ( $file as $str ){
if(preg_match("/^$string$/i",$str)){
$count++;
}

}
echo "$string found $count times";
?>

2006-07-10 12:12:04 · answer #3 · answered by oc_surf 2 · 0 0

foreach ( $str in $file )
{

wont work dude, you gotta use a reg expression

2006-07-04 09:14:19 · answer #4 · answered by bow4bass 4 · 0 0

fedest.com, questions and answers