trying to get two word phrases from an array but I keep getting one word phrases with a white space either before or after the word.
$text = preg_replace(array('/\s{2,}/', '/[\t
]/'), ' ', $text);
$textarray = explode(" ", $text);
array_filter($textarray);
$textCount = array_count_values($textarray);
arsort($textCount);
$twoWords = array();
for ($i = 0; $i<=count($textarray); ++$i) {
if ($textarray[$i]<>" ") {
$twoWords[$i] = $textarray[$i]." ".$textarray[$i + 1];
} else {
$twoWords[$i] = "blah";
}
}
foreach ($twoWordsCount as $tey => $val2) {
if ($tey == null || $tey == "" || $tey == "
" || $tey == "\t" || $tey == "" || $tey == "
" || $tey == " " || $tey == " " || $tey == " ") {
//do nothing
} else {
echo $val2."
";
}
}
and for some reason this just returns values likes whitespace Hello or Test and then a whitespace, but I want it to return hello test