You could use strpos--there are easier ways if you don't need the
offsets.

Example:

<?php

$inputstring = " This is   a  string  ";
$pos = 0;
$oldpos = 0;
$result = array();
$inputstring .= ' ';

while (!(($pos = (strpos ($inputstring, ' ', $pos))) === false))
{
        if ($pos != $oldpos)
                $result [substr ($inputstring, $oldpos, $pos - $oldpos)] = $oldpos;
        $pos++;
        $oldpos = $pos;
}

print_r ($result);

?>

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 magazine dedicated to PHP programmers

Come visit us at http://www.phparch.com!
--- Begin Message ---
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. 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.


-- 
bye,
 Uros


-- 
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

Reply via email to