I'm developing a word counting application and I'm using following code to load words to an array.
$str = ' Some string is here ... Another string.. ';
$str = trim($str);
$str = preg_replace('/\s+/', ' ', $str);
$str_array = explode(" ", $str);
$str_array = array_filter($str_array);
But the issue is I'm getting empty values in my array like follows.
Array
(
[0] => Word1
[1] => Word2
[2] => Word3
[3] =>
[4] =>
[5] =>
)
I've tried array_filter($str_array)
and more stackoverflow answers. But I was failed to get this done. Can some one please help me to fix this issue? Thanks!