所以...我计算所有preg_match的出现次数和求和/添加它的第一部分(“/”之前的数字)有问题。我只想在“/”之前得到数字的平均值。真的很抱歉英文不好。PHP count and sum preg_matches
的script.php
$wyniki=file("wyniki.txt");
foreach($wyniki as $w)
{
preg_match("/^([0-9]{1})\/([0-9]{1})$/",$w,$ar);
if(!empty($ar)){
print_r($ar[1].'/'.$ar[2]);
echo("\n");
}
}
script2.php(失败,但script.php的其他方式)
$file=fopen("wyniki.txt", "r");
$read=fread($file, filesize("wyniki.txt"));
echo($read."\n");
//if($read!=trim(''))
//{
preg_match("/^([0-9]{1})\/([0-9]{1})$/",$read,$ar);
//print_r($ar[1].'/'.$ar[2]);
print_r($ar);
echo("\n");
//}
fclose($file);
wyniki.txt
5/5
asd
4/5
fgh
提示:'[0-9] {1}'可被写为'[0-9]'单独。添加'{1}'有点像说“一个苹果是一个苹果”。字符类将自己匹配一个数字。 – 2012-03-20 17:52:35
你在这里做什么?您的正则表达式看起来不错(参见http://www.regexplanet.com/advanced/java/index.html) – haltabush 2012-03-20 17:54:10
我的问题在于创建获取平均值的代码。我所有的尝试,甚至计数$ AR失败;) – crusty 2012-03-20 18:06:44