how about ...
Nope. The question was the position of the words, not how many times
they appear.
oops :(
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
> > 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 a
Uros Gruber wrote:
Hi!
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
> Yes, but my example was geared towards trying to work through a more
> generic scenario. I'll bet if you try using perl regex with callback
> it'll be even faster.
I'll take that bet and say using preg_*_callback will be slower. :) I'll try
and time each of them tonite and post what I find.
Som
Yes, but my example was geared towards trying to work through a more
generic scenario. I'll bet if you try using perl regex with callback
it'll be even faster.
Marco
--
php|architect - The magazine for PHP Professionals
The monthly worldwide magazine dedicated to PHP programmers
Co
Hi!
I have dome almost the same
$input = 'Today is a very beautiful day and the sun is shining';
$output = array();
$words = explode(' ',$input);
$cur_pos = 0;
foreach($words as $word) {
if(!empty($output[$word])){
$output[$word] .= ','.$cur_pos;
} else {
$output[$word]
onals. Get your copy
today. http://www.phparch.com/
> -Original Message-
> From: Marco Tabini [mailto:[EMAIL PROTECTED]]
> Sent: Monday, December 16, 2002 12:37 PM
> To: [EMAIL PROTECTED]
> Cc: 'Uros Gruber'; PHP-General
> Subject: RE: [PHP] Divide into words
>
John,
I'm not sure this will work if there is more than one space between
words.
Also, my previous example won't work if there are duplicate words
(although it's easy to make an array out of each word and solve the
problem), nor if the words are delimited by any character other than
spaces, in wh
> 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
You could use strpos--there are easier ways if you don't need the
offsets.
Example:
This is from memory, but it looks like it should work even for weird
strings like the one above.
Cheers,
Marco
--
php|architect - The magazine for PHP Professionals
The monthly worldwide magazin
Hi!
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.
11 matches
Mail list logo