Last active
November 23, 2023 14:42
-
-
Save victory-sokolov/0a9a5621dfc518f669958d6166a0d84b to your computer and use it in GitHub Desktop.
PHP count words in string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wordCount() { | |
$description = "Hello there"; | |
$string = preg_replace('/\s+/', ' ', trim($description)); | |
$words = explode(" ", $string); | |
return count($words); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment