Hi Rob - thanks again for your quick reply - I really appreciate it! So, the last solution didn’t work either. What I’m trying to do is take a file (2918022.htm) and search the PCT column for scores > 60. Typically the htm file looks like this (but it can be different sometimes):
[code]
Thursday Afternoon Pairs Thursday Aft Session February 22, 2018
Scores after 8 rounds Average: 72.0 Section A North-South
Pair Pct Score Section Rank Overall Rank MPs
A B C A B C
6 62.85 90.50 A 1 2 1.97(OA) Jane Smith - Bob Stanley
4 55.56 80.00 A 2 5 0.83(OA) Duane Jones - Karen Jones
2 54.51 78.50 C 3 1 1 3 2 0.77(OC) Ann Sinclair - Carol Heller
5 46.88 67.50 B 2 4 0.51(OB) Jacqueline Kirby - Jane Hope
1 45.83 66.00 C 3 0.57(OC) Chris Bruce - David Tanner
3 42.71 61.50 A Kimberly Griffin - Judy Manus
7 41.67 60.00 C John Ramsey - Sue Martinez
Thursday Afternoon Pairs Thursday Aft Session February 22, 2018
Scores after 8 rounds Average: 72.0 Section A East-West
Pair Pct Score Section Rank Overall Rank MPs
A B C A B C
8 71.43 102.86 B 1 1 1 1 2.63(OA) Ray McDonough - Jackie Bailey
4 62.70 90.29 A 2 3 1.48(OA) Bill Ready - Peggy McBride
3 59.52 85.71 C 3 2 1 4 2 1 1.11(OA) George Harrison - Rudy Marquez
6 53.17 76.57 A John Burtson - Joy Kenny
7 46.03 66.29 A Fred Douglas - Margie Hennley
1 38.89 56.00 C 2 0.22(SC) Herbert Dorf - Lawrence Hoover
2 36.51 52.57 C Jean Stein - Minnie Brown
5 31.74 45.71 C Marlene Williams - Albert Hayes
[/code]
Once there is a match, get each entire line (i.e. 6 62.85 90.50 A 1 2 1.97(OA) Jane Smith - Bob Stanley), turn it red, and write it back into the original file and echo the new file on screen. Again, typically the file is only text and very small in size.
So, my entire code looks like this:
[php]
#get file
$unitfile = $_SERVER[‘DOCUMENT_ROOT’] . $path;
#if file exists
if($unitfile){
$max = 60;
$arr = array_filter(file($unitfile,FILE_SKIP_EMPTY_LINES),function($v){
return (!empty(trim($v)));
});
$file = array_values(array_filter(array_map(function($v) use ($max){
preg_match_all('/[0-9]{1,3}\.[0-9]{1,2}/',$v,$match);
$match = (!empty($match[0]) && count($match[0]) == 3)? $match[0] : false;
if(empty($match))
return false;
if($match[0] < $max)
return false;
preg_match('/(.*) - (.*)/',$v, $wholelinescore);
return [
'entirety' => $wholelinescore[0]
];
},$arr)));
foreach($file as $item) {
$beforeChange = $item[‘entirety’];
$afterChange = “” . $beforeChange . ‘’;
$newscoresheet = str_replace($beforeChange, $afterChange, $arr);
}
echo ‘
’ . implode($newscoresheet) . ‘
’;
}
[/php]
So the code above works without errors except it only turns the last match red instead of all matches red (in the file above there are 3 matches).
I think the error is in my loop - particularly with assigning $item[‘entirety’] to a var.
if echo $item['entirety]; prints out all matches then why does $beforeChange = $item[‘entirety’]; or event $beforeChange .= $item[‘entirety’]; get all matches?
BTW, I did take your advice and changed my naming conventions - thanks!