如何使用strlen()在php中查找字符串长度?

mym*_*and 10 php string

如何在php中找到字符串的长度而不使用strlen()

Vai*_*ain 13

我知道这是一个相当古老的问题,但这段代码对我有用.

$s = 'string';
$i=0;
while ($s[$i] != '') {
  $i++;
}
print $i;
Run Code Online (Sandbox Code Playgroud)


Nar*_*yan 6

 $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)

而-迭代字符串的字符11

$i - 给出字符串的最终计数.

isset($inputstring[$i]) - 检查字符是否存在(null).


Cra*_*ite 3

让我们变得愚蠢

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)