jaikar Posted February 4, 2011 Share Posted February 4, 2011 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 More sharing options...
litebearer Posted February 4, 2011 Share Posted February 4, 2011 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 Link to comment https://forums.phpfreaks.com/topic/226665-logic-needed-for-word-processing/#findComment-1169788 Share on other sites More sharing options...
jaikar Posted February 4, 2011 Author Share Posted February 4, 2011 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? Link to comment https://forums.phpfreaks.com/topic/226665-logic-needed-for-word-processing/#findComment-1169822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.