for example i have sentenes like this:
$text = \"word, word w.d. word!..\";
I need array like this
Array
(
[0] => w
use
str_word_count ( string $string [, int $format = 0 [, string $charlist ]] )
see here http://php.net/manual/en/function.str-word-count.php it does exactly what you want. So in your case :
$myarray = str_word_count ($text,1);
Use the function explode, that will split the string into an array
$words = explode(" ", $text);
Using preg_split
with a regex of /[^\w]*([\s]+[^\w]*|$)/
should work fine:
<?php
$text = "word word w.d. word!..";
$split = preg_split("/[^\w]*([\s]+[^\w]*|$)/", $text, -1, PREG_SPLIT_NO_EMPTY);
print_r($split);
?>
DEMO
Output:
Array
(
[0] => word
[1] => word
[2] => w.d
[3] => word
)