<?php
$test = <<<'EOF'
анон тестировал testiroval da оп_хуй как-то $op_hui $mamkuEbal
EOF ;
/**
* Ну нихуя себе, пхпдок!
* @param string $text текст который будем парсить
* @return array|false результат в формате 'wordsNumber'=>количество слов,
* 'words'=>$result , где результ в формате слово=Ю количество вхождений,
* либо фолс если что-то пошло не так
*/
function countWords( $text ) {
return false ;
}
$wordRegexp = "/[а-яa-zё\-]+/ui" ;
$words = $pregResult [ 0 ] ;
$result = [ ] ;
foreach ( $words as $word ) {
if ( isset ( $result [ $word ] ) ) { $result [ $word ] ++;
} else {
$result [ $word ] = 1 ;
}
}
return [
'wordsNumber' => $count ,
'words' => $result
] ;
}
$parsedText = countWords( $test ) ;
if ( ! $parsedText ) {
echo "Сасай" ;
} else {
echo "Всего слов в тексте - {$parsedText['wordsNumber']} " . PHP_EOL;
foreach ( $parsedText [ 'words' ] as $word => $occurrence ) {
echo "$word - встречается $occurrence раз" . PHP_EOL;
}
}
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CgokdGVzdCA9IDw8PCdFT0YnCtCw0L3QvtC9INGC0LXRgdGC0LjRgNC+0LLQsNC7IHRlc3Rpcm92YWwgZGEg0L7Qv1/RhdGD0Lkg0LrQsNC6LdGC0L4gJG9wX2h1aSAkbWFta3VFYmFsCkVPRjsKCi8qKgogKiDQndGDINC90LjRhdGD0Y8g0YHQtdCx0LUsINC/0YXQv9C00L7QuiEKICogQHBhcmFtIHN0cmluZyAkdGV4dCDRgtC10LrRgdGCINC60L7RgtC+0YDRi9C5INCx0YPQtNC10Lwg0L/QsNGA0YHQuNGC0YwKICogQHJldHVybiBhcnJheXxmYWxzZSDRgNC10LfRg9C70YzRgtCw0YIg0LIg0YTQvtGA0LzQsNGC0LUgJ3dvcmRzTnVtYmVyJz0+0LrQvtC70LjRh9C10YHRgtCy0L4g0YHQu9C+0LIsCQogKiAnd29yZHMnPT4kcmVzdWx0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