hi dore,
Dore Van Hoorn wrote:
> # 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
maybe you can replace your unwanted chars with preg_replace()
i.e.: $textStripped = preg_replace("/[.:;]/", "", $textInterPuncted);
> # 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?
how about this:
if(array_key_exists($wordInText, $occurences))
{
$occurences[$wordInText]++;
}
else
{
$occurences[$wordInText] = 1;
}
> # 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.
look at the array-stucture with print_r, var_dump, var_export, ...
or loop through the array:
echo "<table>";
foreach($occurences as $word => $count)
{
echo "<tr><td>$word</td><td>$count</td></tr>"
}
echo "</table>";
hope this helps. (didn't test the code, just wote it from brain. but the
manual would be your friend)
ciao SVEN
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php