<?php
$pointer = fopen('php.txt', 'r');
$string = fread($pointer, filesize('php.txt'));
$length = strlen($string);
$word = "";
$words = array();
for($i = 0; $i < $length; $i++){
if(ord($string[$i]) == 13){
continue;
}
if($string[$i] == " " || $i == $length - 1 || $string[$i] == "\n"){
if($i == $length - 1){
$word .= $string[$i];
}
if(!empty($word)){
$words[] = $word;
}
$word = "";
}else{
$word .= $string[$i];
}
}
//for determine frequency
$frequency = array();
foreach ($words as $word) {
if(array_key_exists($word, $frequency)){
$frequency[$word] ++;
} else {
$frequency[$word] = 1;
}
}
foreach($frequency as $key => $value){
echo "$key => $value <br>";
}
$pointer = fopen('php.txt', 'r');
$string = fread($pointer, filesize('php.txt'));
$length = strlen($string);
$word = "";
$words = array();
for($i = 0; $i < $length; $i++){
if(ord($string[$i]) == 13){
continue;
}
if($string[$i] == " " || $i == $length - 1 || $string[$i] == "\n"){
if($i == $length - 1){
$word .= $string[$i];
}
if(!empty($word)){
$words[] = $word;
}
$word = "";
}else{
$word .= $string[$i];
}
}
//for determine frequency
$frequency = array();
foreach ($words as $word) {
if(array_key_exists($word, $frequency)){
$frequency[$word] ++;
} else {
$frequency[$word] = 1;
}
}
foreach($frequency as $key => $value){
echo "$key => $value <br>";
}
No comments:
Post a Comment