apie/count-words

Composer package of the apie library: count words

Maintainers

👁 pjordaan

Package info

github.com/apie-lib/count-words

pkg:composer/apie/count-words

Statistics

Installs: 7 016

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0-RC2 2025-03-18 22:52 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

Replaces

None

MIT 68d0124856f17a38dded79b4c767ba2303c6962a

  • Pieter Jordaan <pieter_jordaan.woop@hotmail.com>

This package is auto-updated.

Last update: 2026-06-29 02:13:43 UTC


README

👁 Image

count-words

👁 Latest Stable Version
👁 Total Downloads
👁 Latest Unstable Version
👁 License
👁 PHP Composer

👁 PHP Composer

This package is part of the Apie library. The code is maintained in a monorepo, so PR's need to be sent to the monorepo

Documentation

This small package contains a class to count words in a text. All words are returned lowercase.

Usage

use Apie\CountWords\WordCounter;

var_dump(WordCounter::countFromString('This is the text with many words like the or and'));

This will echo:

array(10) {
 ["this"]=>
 int(1)
 ["is"]=>
 int(1)
 ["the"]=>
 int(2)
 ["text"]=>
 int(1)
 ["with"]=>
 int(1)
 ["many"]=>
 int(1)
 ["words"]=>
 int(1)
 ["like"]=>
 int(1)
 ["or"]=>
 int(1)
 ["and"]=>
 int(1)
}

It also supports reading (large) files as long the indexing does still fit in memory:

use Apie\CountWords\WordCounter;

var_dump(WordCounter::countFromResource(fopen('large_file.txt', 'r')));