Vai*_*ain 13
我知道这是一个相当古老的问题,但这段代码对我有用.
$s = 'string';
$i=0;
while ($s[$i] != '') {
$i++;
}
print $i;
Run Code Online (Sandbox Code Playgroud)
$inputstring="abcd";
$tmp = ''; $i = 0;
while (isset($inputstring[$i])){
$tmp .= $inputstring[$i];
$i++;
}
echo $i; //final string count
echo $tmp; // Read string
Run Code Online (Sandbox Code Playgroud)
而-迭代字符串的字符1
由1
$i
- 给出字符串的最终计数.
isset($inputstring[$i])
- 检查字符是否存在(null).
让我们变得愚蠢
function stupidCheck($string)
{
$count = 0;
for($i=0; $i<66000; $i++)
{
if(@$string[$i] != "")$count++;
else break;
}
return $count;
}
Run Code Online (Sandbox Code Playgroud)