Core Function CountWords
From Sputnik Wiki
CountWords( <string>, <format>, <charlist> )
Contents |
Description
Return information about words used in a string.
Parameters
string
The string to use.
format
Specify the return value of this function. The current supported values are:
0 - returns the number of words found
1 - returns an array containing all the words found inside the string
2 - returns an associative array, where the key is the numeric position of the word inside the string and the value is the actual word itself
charlist
A list of additional characters which will be considered as 'word'
Return Value
Success: Returns an array or an integer, depending on the format chosen.
Failure: Returns null.
Remarks
None
Example
// Display how many words are found my $Str = "The quick brown fox"; echo CountWords($Str), @NL; // Prints 4 // Return an array containing all the words found inside the string my $Str = "The quick brown fox"; printr CountWords($Str, 1); // Prints // ARRAY // { // [0] => The // [1] => quick // [2] => brown // [3] => fox // } // Return an associative array, where the key is the numeric position // of the word inside the string and the value is the actual word itself my $Str = "The quick brown fox"; printr CountWords($Str, 2); // Prints // ARRAY // { // [0] => The // [4] => quick // [10] => brown // [16] => fox // }