You need to process each byte in a string individually.
Loop through each byte in the string with for. Example 1-17 counts the vowels in a string .
Processing each byte in a string
Processing a string a character at a time is an easy way to calculate the "Look and Say" sequence, as shown in Example 1-18.
The "Look and Say" sequence
Example 1-18 prints:
1 11 21 1211 111221 312211 13112221 1113213211 31131211131221 13211311123113112211
It's called the "Look and Say" sequence because each element is what you get by looking at the previous element and saying what's in it. For example, looking at the first element, 1, you say "one one." So the second element is "11." That's two ones, so the third element is "21." Similarly, that's one two and one one, so the fourth element is "1211," and so on.
1.4.4. See Also
Documentation on for at http://www.php.net/for; more about the "Look and Say" sequence at http://mathworld.wolfram.com/LookandSaySequence.html.