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 which case regex are probably our best bet.
Cheers,
Marco
--
------------
php|architect - The magazine for PHP Professionals
The monthly worldwide magazine dedicated to PHP programmers
Come visit us at http://www.phparch.com!
--- Begin 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.
Well you could've at least shown us what you had so far instead of
letting us solve the problem for you:
$string = "Today is a very beautiful day and the sun is shining";
$words = explode(" ",$string);
$pos = 0;
foreach($words as $word)
{
if(isset($w[$word]))
{ $w[$word] .= ",$pos"; }
else
{ $w[$word] = $pos; }
$pos += strlen($word) + 1;
}
print_r($w);
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php