individual bytes in the string need to be processed separatelybyte-wise processing of strings<?php/** Each byte in the string needs to be processed separately* Byte-wise processing of strings */$string = "This weekend, I ' m going shopping for a pet chicken.";$vowels = 0;for ($i = 0, $j = strlen ($string); $i < $j; $i + +) {if (strstr (' Aeiouaeiou ', $string [$i])) {$vowels + +; }}function Lookandsay ($s){ /** 1211* $m = 1* $n = 1* $r = One* $m = 2* $n = 1 *///Initialize the return value to an empty string$r = ";//$m contains the characters to be counted, initialized to the first character in a string$m = $s [0];//var_dump ($m);d ie;//$n is the number of $m that have been viewed, initialized to 1$n = 1;//If this character is the same as the previousfor ($i = 1, $j = strlen ($s); $i < $j; $i + +) {//If this character is the same as the previousif ($s [$i] = = $m) {$n + +;} else {//Otherwise append the $n character number and the character itself $m to the return value$r. = $n. $m; //It's time to find the next character, set the character you're looking for as the current character.
$m = $s [$i]; //and re-reset the number to 1
$n = 1; } }return $r. $n. $m;}$s = 1;For ($i = 0; $i < $i + +) {$s = lookandsay ($s);echo "$s <br>";}//Print results
1.4 Byte Processing string