Listing 1751
Submitted by DaRooster, 13 November 2008
I'm trying to search a file (which exists) and search for a line with a specific string, then when found, grab the NEXT line in the file.... (IE, I want to grab the full line AFTER the string-matching line)
Here's my code, and here is the output:
START OUTPUT:
The file /usr/local/apache/htdocs/squirrelmail/data/bennettr-spamrc exists
with 22 lines
this file did not have a Spam-Status tag line or did not have a followup
record
START CODE:
// Assign SPAMRC file
$spamrcfile = "/usr/local/apache/htdocs/squirrelmail/data/$key-spamrc";
// Count # of lines in SPAMRC
$linemax = count(file($spamrcfile));
if (file_exists($spamrcfile)) {
echo "The file $spamrcfile exists with $linemax lines";
} else {
echo "The file $spamrcfile does not exist";
}
$i = 0; while(strpos($line[$i],"Spam-Status")<0 and $i<=$linemax) $i += 1;
if ($i<=$linemax) $i += 1;
while($i<=$linemax and strlen(trim($line[$i]))<2 ) $i += 1; // found
Spam-Status now getting first following non blank rec
if ($i>$linemax) print ("<br>this file did not have a Spam-Status tag line
or did not have a followup record");
else {
$answer = $line[$i];
// do your processing of $answer now
