Hello,

This is a reply to an e-mail that you wrote on Thu, 26 Jun 2003 at 12:26,
lines prefixed by '>' were originally written by you.
> # 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

This is not tested but should work:
$words = preg_split("/[^A-Z0-9]/i",$originaltext);

> # i would like a function that pushes this word into a second array.
> # before pushing, it has to check whether or not the same word is
> already
> in the array.
> # if it is: do not push word into array, but add "1" to the number of
> occurrences
> of that word
> # if it is not: push this new word into array
> # all of this has to result into a word - frequency array (content
> analysis
> of free text)
> # question 1: how do i produce such an array?
> # question 2: how do i get the two elements (word and number of
> occurrences)
> # together out of the array and print them to the screen?
> # f.e.: the word "computer" occurred two times in this text.

Try using the words as the key to the array and the number of times it
occoured as the value, so...

foreach($words as $thisword){
    if(in_array($thisword, $array)){
        $array[$thisword]++;
    } else {
        $array[$thisword]=1;
    }
}

foreach($array as $word=>$count){
    echo "The word $word occoured $count times\n";
}

HTH

David.

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

          Professional Web Development by David Nicholson
                    http://www.djnicholson.com/

    QuizSender.com - How well do your friends actually know you?
                     http://www.quizsender.com/
                    (developed entirely in PHP)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to