배열에서 두 단어 구를 얻으 려하지만 단어 앞이나 뒤에 공백이있는 한 단어 구를 계속 가져옵니다. PHP 배열은 여전히 공백과 null을 얻고 있습니다
$text = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $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 == "\r\n" || $tey == "\t" || $tey == "\r" || $tey == "\n" || $tey == " " || $tey == " " || $tey == " ") {
//do nothing
} else {
echo $val2."\n";
}
}
이 그냥 값을 반환 어떤 이유로
는 공백 안녕하세요 또는 테스트 후 공백을 좋아하지만, 나는 그것이 시험에게 인사 반환 할
시도'trim()'? – Blake
당신이 사용하고있는'$ text'를 제공 해주실 수 있습니까 – Julien
입력 데이터는 어떻게 생겼습니까? –