Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:substr跑道环路_Php_Loops - Fatal编程技术网

PHP:substr跑道环路

PHP:substr跑道环路,php,loops,Php,Loops,这是我代码的一部分 $hold = $this->content; $hold_table = array(); for($i=0; $i<strlen($hold); $i++){ $t = substr($hold, $i, 10); $count = substr_count($hold, $t); if($count > 1){ $hold = str_replace($t,

这是我代码的一部分

    $hold = $this->content;
    $hold_table = array();
    for($i=0; $i<strlen($hold); $i++){
        $t = substr($hold, $i, 10);
        $count = substr_count($hold, $t);
        if($count > 1){
            $hold = str_replace($t, '', $hold); //Just iterating for now to get counts
            $hold_table[bin2hex($t)] = $count;
        }
    }
$hold=$this->content;
$hold_table=array();
对于($i=0;$i 1){
$hold=str_replace($t,,$hold);//现在只是迭代以获取计数
$hold_table[bin2hex($t)]=$count;
}
}
$this->content
是一个读入的文件

如果此行中的“10”:(
$t=substr($hold,$i,10)
为10或更低,它工作正常,并能很好地输出结果

如果我把10改成“15”。脚本只是挂起在一个循环中

我认为没有任何数组键大小限制,如果
$I>strlen($hold)


你知道为什么从10变为15会导致混乱吗?

你正在通过stru-replace语句改变$hold(基本上缩短它)。我想这会产生一些意想不到的结果。

我可以毫无问题地将自己推到14岁。你正在尝试做一些非常奇怪的事情。循环遍历字符串,直到它结束。在每次迭代中,您都尝试从当前字符开始获取长度为10的子字符串。所以,我真的不明白为什么会这样。当
$i
strlen($hold)-1
时,您希望
substr
返回什么?当然,它足够聪明,不会崩溃,但仍然是相当奇怪的正确方法。但是如果字符串匹配不止一次,我就把它拔出来,这样我就有理由离开它所在的柜台。我希望通过重复尽可能多地消除字符串。你是不是建议我在下一个循环之前检查strlen来发现这个错误?当for循环捕捉到这一点时,这似乎是不必要的。这段代码的最终目标是什么?也许它可以通过
g
modifier来实现?这是一个基本的压缩…字节配对。我只是在第一次通过时使用更高的数字来获得更好的压缩效果。也许我会坚持传统的字节配对。