This is the default.
1: Same as 0, but returns only those byte values with a frequency greater than zero.
2: Same as 0, but returns only those byte values with a frequency of zero.
3: Returns a string containing all located byte values.
4: Returns a string containing all unused byte values.
The following example counts the frequency of each character in $sentence:
$sentence = "The rain in Spain falls mainly on the plain";
// Retrieve located characters and their corresponding frequency.
$chart = count_chars($sentence, 1);
foreach($chart as $letter=>$frequency)
echo "Character ".chr($letter)." appears $frequency times
";
?>
272 CHAPTER 9 ?– STRINGS AND REGULAR EXPRESSIONS
This returns the following:
Character appears 8 times
Character S appears 1 times
Character T appears 1 times
Character a appears 5 times
Character e appears 2 times
Character f appears 1 times
Character h appears 2 times
Character i appears 5 times
Character l appears 4 times
Character m appears 1 times
Character n appears 6 times
Character o appears 1 times
Character p appears 2 times
Character r appears 1 times
Character s appears 1 times
Character t appears 1 times
Character y appears 1 times
Counting the Total Number of Words in a String
The function str_word_count() offers information regarding the total number of
words found in a string. Its prototype follows:
mixed str_word_count(string str [, int format])
If the optional parameter format is not defined, it will simply return the total number
of words.
Pages:
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347