嗨,下面的代码向我展示了从带有条件的文本文件中选择行。我想知道我是否可以数出这些行,希望有一种简单的方法可以做到这一点,即不使用数组.....有什么帮助吗?
使用$count
变量来跟踪。
这应该工作-
$count = 0;
foreach($lines as $line)
{
// Check if the line contains the string we're looking for, and print if it does
if(strpos($line, $search) !== false){
$count++;
echo '<p> '.$line.' </p>';
}
}
echo $count;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句