cakeCount行,包含单词“;noreply@118-bonsplans.com";以及“;失败”;在csv


cakeCount line that contain the word "noreply@118-bonsplans.com" and "fail" in csv file using php

我有如下acct-2012-08-24-0001.csv文件:

noreply@118-bonsplans.com   toulouse@texa.fr    relayed
noreply@lemeilleur-duweb.com  g.dupond@libertysurf.fr   failed
noreply@118-bonsplans.com   toulouse@texa.fr    failed
noreply@lemeilleur-duweb.com  g.dupond@libertysurf.fr   relayed

我只想在csv文件中计数noreply@118-bonsplans.com toulouse@texa.fr failed,但我不知道如何计数。任何知道的人都可以帮我,谢谢。

我不确定,但这可能对你有用。

count(preg_grep("/noreply@lemeilleur-duweb.com  g.dupond@libertysurf.fr   relayed/", file("acct-2012-08-24-0001.csv")));

您也可以使用if block中的AND条件逐个检查它的内容。

使用preg_match_all()

$match = preg_match_all('/noreply@118-bonsplans.com('s+)toulouse@texa.fr('s+)failed/i', $csv, $matches);
echo count($matches[0]);

这里有一个简单的方法。。。

$fp = fopen('acct-2012-08-24-0001.csv');
$count = 0;
while ($row = fgetcsv($fp)) {
    if (
        $row[0] == 'noreply@118-bonsplans.com'
        && $row[1] == 'toulouse@texa.fr'
        && $row[2] == 'failed'
    ) {
       $count++;
    }
}
echo "$count matches found";
?>