PHP port of iarna/word-count. This should provide an accurate wordcount taking into account apostrophes and hyphens and stuff. See iarna's project for disclaimers on what languages this method may not work well with.
composer require sylae/word-count
<?php
use Sylae\Wordcount;
$string = "This string has five words!";
$count = Wordcount::count($string); // int(5)
I mean if you want to cool i guess <3
- PSR-2.
- Write tests.
- Yeet me a PR.
I'm lowkey pretty sure ::count()
could be improved with fancy regex magic, but I'm a dumb bitch so idk.
semver.
MIT.