Jump to content

logic needed for word processing ?


jaikar

Recommended Posts

hi there,

 

i have a project to submit in college, its like user uploads a sentence of letters in a text file, it can be 5000 words to one million, now the code need to process it and display how many unique words, how many times the word have repeated itself, and couple of more data.. i am confused which way i should do this, should i use an explode on so many words? or loop through each words and store them in an array, but the array may get too bulky? will it slow down the server? or terminate script etc?.. please show some light on this..

 

thankyou very much in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/226665-logic-needed-for-word-processing/
Share on other sites

Perhaps something like...

Psuedo code

$file = "mywords.txt";
$text = file_get_contents($file);
$text_array = explode(" "; $text);
$text_array = array_unique($text_array);
$n = count($text_array);
echo $n;

OR

create a loop where your read the file in 'chunks' using fread, process each chunk - note if a chunk does not end in a space, find the last space in the current chunk and adjust 'chunk' size appropriately

great man!.. i love the chunks idea! .. i think that will really help... really thanks for your time!..

 

also, does explode function actually loops in the background or it does it in a different way ? which is better, looping through the words manually or just use the explode option? OR both are same?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.