This extension count words and sort them by the number and alphabet.
The preferred way to install this extension is through composer.
Either run
php composer.phar require prokhonenkov/yii2-word-counter
or add
"prokhonenkov/yii2-word-counter": "*"
to the require section of your composer.json
file.
Add component declaration to your config file for console config:
<?php
return [
// ... your config
'components' => [
'wordCounter' => [
'class' => \prokhonenkov\wordcounter\WordCounter::class,
],
]
];
Pass filepath to setFilePath method and invoke count method.
class TextController extends \yii\console\Controller
{
public function actionCountWords(string $fileName)
{
$result = \Yii::$app->wordCounter
->setFilePath($fileName)
->count();
print_r($result);
}
}