RE: [PHP] Divide into words
| From: | John W. Holmes | Date: | Tue, 17 Dec 2002 02:17:18 +0000 |
| Subject: | RE: [PHP] Divide into words | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-128497@lists.php.net to get a copy of this message | ||
> > For example i have some words:
> >
> > Today is very beautiful day and sun is shining
> >
> > What i want to get from this is array
> >
> > words
> > [Today] => 0
> > [Is] => 6,30
> > [Very] => 8
> > [beautiful] => 12
> > ......
> >
> > Can somebody please help me with this. Those nubers are
> > position of special word in above sentence. If word repeates
> > i want to have both positions saved in same row like word is.
> >
> > I tried something but i think it's to lame.
> >
> >
>
> how about ...
>
> <?
>
> $sentance = "Today is a beautiful day. ";
> $temp = preg_replace("/[^a-zA-Z]+/", " ", $sentance);
> $temp = explode(' ', $temp);
> $words = array_count_values($temp);
>
> print_r($words);
Nope. The question was the position of the words, not how many times
they appear.
---John Holmes...