Recommend this page to a friend! |
All requests | > | What is the best PHP count words class? | > | Request new recommendation | > | Featured requests | > | No recommendations |
by Omotayo Odupitan - 5 days ago (2016-10-25)
+2 | I need to count the number of words in a string. |
1. by Oleg Zorin - 4 days ago (2016-10-27) Reply
Good day, Omotayo Odupitan.
<code>
<?php
function wordsCounter($string) {
$string = preg_replace('/[^[:alpha:]]+/', ' ', $string);
return count(explode(' ', $string));
}
2. by Omotayo Odupitan - 3 days ago (2016-10-27) in reply to comment 1 by Oleg Zorin Comment
Thank you Oleg Zorin.
Much appreciated.
+2 | by Manuel Lemos 15990 - 1 hour ago (2016-10-31) Comment If you need a package that works well with UTF-8 and does not depend on the PHP extensions avaliable on your system, that package can solve your problem of counting words. |
1. by Omotayo Odupitan - 1 hour ago (2016-10-31) Reply
Thanks Manuel.
Recommend package | |
|