Hello,
I’m wondering if anyone can tell me why the keys in the array returned from str_word_count don’t increment by 1 per word, but instead seem to count each character in a word as a single array member. See the example below, where each key is several numbers higher than the previous (eg, first key is 1, second is 6, third is 15, etc, instead of 1,2,3), with the increment evidently being based on the number of characters in each word plus a space on either side:
Example string:
“Tonight, we will make history for our country and progress for the American people,’’ said Speaker of the House, Nancy Pelosis, in her closing argument …”
returns:
Array ( [1] => quot [6] => Tonight [15] => we [18] => will [23] => make [28] => history [36] => for [40] => our [44] => country [52] => and [56] => progress [65] => for [69] => the [73] => American [82] => people [100] => said [105] => Speaker [113] => of [116] => the [120] => House [127] => Nancy [133] => Pelosis [142] => in [145] => her [149] => closing [157] => argument [167] => b [174] => b )
If anyone can tell me how I can get this array to return a predictably incrementing array based on words rather than characters, it would be most appreciated!
EN