+ -
当前位置:首页 → 问答吧 → 文件行数的统计

文件行数的统计

时间:2011-09-07

来源:互联网

一个文本文件,文件格式如下
asdfasdfas---YES---
asdfasdfasdf---YES---
vbsrd---YES---
uyioyuio---NO---
hj---YES---
ljj---YES---
ppop---YES---
mfjrtscf---NO---

在每行字符串中,都有“---YES---”或“---NO---”,我想统计包含“---YES---”和“---NO---”的行数,方法如何写?谢谢

作者: sw4419   发布时间: 2011-09-07

PHP code


$contents=file_get_contents("testx.txt");
$lines = explode("\n",$contents);
$yes_nums = $no_nums = 0 ; 
for ($i=0;$i<count($lines);$i++){
    if (strpos($lines[$i],"---YES---") !==FALSE ){
        $yes_nums++;
    }
    if (strpos($lines[$i],"---NO---") !==FALSE ){
        $no_nums++;
    }
}
echo $yes_nums;
echo $no_nums;


作者: fenyao   发布时间: 2011-09-07

en wo zenme shuru buliao zhongwen ne

作者: zhouhb1   发布时间: 2011-09-07