Re: Find/count different word in a text
| From: | Matijn Woudt | Date: | Wed, 25 Apr 2012 17:26:05 +0000 |
| Subject: | Re: Find/count different word in a text | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-317680@lists.php.net to get a copy of this message | ||
On Wed, Apr 25, 2012 at 6:59 PM, Karl-Arne Gjersøyen
<karlarneg@gmail.com> wrote:
> Hello again.
> I am looking for a way to find and count different word in a text..
> I am thinking on save the text as array and iterate through the array.
> Then I like to register all different words in the text.
> For example. If bread is used more than one time, I will not count it.
> After the check were I have found single (one) word of every words, I
> count it and tell how many different word that is in the text.
>
> Is this difficult to do? Can you give me a hint for were I shall look
> on www.php.net for a solution to fix this problem? What function am I
> in need of?
>
> Thank you very much.
> Kind Regards, Karl
>
How about:
<?php
$arr = preg_split('/ /', $text);
foreach($arr as $word)
$count[$word]++;
?>
- Matijn