There may be faster ways, for instance using the regular expression function that returns an array of hits, and make the regexp look for 'words' in it with the \b option.
But i will stick to your example code. My suggestions are not tested.
while($myrow = mysql_fetch_row($result)) # as long as there are texts in the database { $text = $myrow[0]; # variabele text contains the text $array = array(); # variabele array is an empty array $modText = strtolower($text); #modify text: string to lower case
//to also split on other signs than only the space $modText=str_replace('.',' ',$modText); $modText=str_replace("\t",' ',$modText); //tab $modText=str_replace("\n",' ',$modText); //newline // add whatever you want
$array = split(" ",$modText); #split text after empty space to create array
of words
$words=array(); for ($word = 0; $word < count($array); $word++) { if (!isset($words[$word] $words[$word]=0; else $words[$word]++; }
sort($words);
for ($word = 0; $word < count($words); $word++) { echo 'The word '. $word.' appears '.$words[$word] .' times !<br> }
# i would like a similar function that removes interpuntuation like "." etc. # all i want remaining in the array are the separate words, all in lower case
sort($array); # sort array elements in alphabetical order
$num = count($array); # count the number of elements in the array
for ($c=0; $c<=$num; $c++) #as long as function has nog reached past last
element in array
NOTE that you are trying to go through the count from 0 to and including count. This is not good. $array($num) does not exist!
So make that
for ($c=0; $c<$num; $c++)
//
werk je voor de uni?{ $wordInText = $array[$c]; #array element is word in text echo "$wordInText<br>"; #print word in text }
+++++++++++++++++++++++++++++++++++ N Dore van Hoorn S s1000454 AlfaInformatica-RuG E [EMAIL PROTECTED] W http://www.let.rug.nl/~s1000454 +++++++++++++++++++++++++++++++++++
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php