The str_word_count() function remains fully available in PHP 8.4 and PHP 8.5. According to the official PHP manual, there are no deprecation notices or behavioral changes for this function in these versions the only changelog entry is from PHP 8.0.0 when the characters parameter became nullable. It is not listed in either the PHP 8.4 or PHP 8.5 deprecation lists.
Output
The function counts words in a string. By default (format 0), it returns an integer. You can change the return type using the format parameter:
<?php
$str = "Hello fri3nd, you re looking good today!";// Format 0 (default): returns word count as integer
echo str_word_count($str); // Output: 7// Format 1: returns array of all words
print_r(str_word_count($str, 1));
/* Output:
Array
(
[0] => Hello
[1] => fri
[2] => nd
[3] => you re
[4] => looking
[5] => good
[6] => today
)
*/// Format 2: returns associative array with word positions
print_r(str_word_count($str, 2));
/* Output (keys are byte positions):
Array
(
[0] => Hello
[6] => fri
[10] => nd
[14] => you re
[29] => looking
[46] => good
[51] => today
)
*/
?>