<?php
/**
* string single display
* string[i] display method
*/
// example
$string = "this is the just text";
$vowels = 0;
for($i = 0, $j = strlen($string); $i < $j; $i++) {
if(strstr('this', $string[$i])) {
$vowels++;
}
}
echo $vowels;
echo "<br>";
function lookandsay($s) {
$r = '';
$m = $s[0];
$n = 1;
for($i = 1, $j = strlen($s); $i < $j; $i++) {
if($s[$i] == $m) {
$n++;
} else {
$r .= $n . $m;
$m = $s[$i];
$n = 1;
}
}
return $r . $n . $m;
}
for($i = 0, $s = 1; $i < 10; $i++) {
$s = lookandsay($s);
echo $s;
echo "<br>";
}
?>
//其实string单个字符操作就是string[$i]的应用
lookandsay很有意思。值得研究!!