Hi I am trying to use if statements to search strings on each line and if it finds matches to the string write to a variable and then echo variable and the loop starts again.
The match is being found fine but anything under the matched record is getting the same value of the variable when there is no match.
I tried if and elseif and i get the same problem this is the code i am using in the loop.
Could somebody help me please.
Basically i just want the $account variable to print only the matches which are correct.
[PHP]$fc=file("./jms/prod/log.txt");
//open same file and use "w" to clear file
$f=fopen("./jms/prod/log.txt","r");
//loop through array using foreach
foreach($fc as $line) {
$lines2 = preg_split('/\s+/', $line);
//echo "<tr><td>$lines 2[7]</td>";
if($lines2[5] > $msgcount) {
$t = "$lines2[5]";
if($t > 4 && $t < 100) {
$alert = '<span class="cream">W ARNING</span>';
}
if($t >= 100 && $t < 500) {
$alert = '<span class="yellow"> ALERT</span>';
}
if($t > 500 && $t < 1000) {
$alert = '<span class="orange"> ALERT - Over 500 msgs</span>';
}
if($t > 1000) {
$alert = '<span class="red">ALE RT - Over 1000 msgs</span>';
}
if($t > 10000) {
$alert = '<span class="red">URG ENT - Over 10000 msgs</span>';
}
if (preg_match("/^SBS.NA.EXCEPTI/", $lines2[1])) {
$account = '<span class="blue">Cl arify</span>';
}
if (preg_match("/^CL.ADAPT/", $lines2[1])) {
$account = '<span class="blue">Cl arify</span>';
}
if (preg_match("/^4499-C/", $lines2[1])) {
$account = '<span class="green">C larify2</span>';
}
if (preg_match("/ITG/", $lines2[1])) {
$account = '<span class="red">RPG </span>';
}
if (preg_match("/PRIMAVE/", $lines2[1])) {
$account = '<span class="blue">PR IMA</span>';
}
if (preg_match("/A.CRM.PAR/", $lines2[1])) {
$account = '<span class="green">c ompany1</span>';
}
if (preg_match("/CRM.PRODU/", $lines2[1])) {
$account = '<span class="green">c ompany1</span>';
}
if (preg_match("/NT.CONTRA/", $lines2[1])) {
$account = '<span class="green">c ompany2</span>';
}
if (preg_match("/NT.PRODU/", $lines2[1])) {
$account = '<span class="green">c ompany3</span>';
}
if (ereg("CRM.LOG$ ", $lines2[1])) {
$account = '<span class="green">C RM LOG</span>';
}
echo "<tr><td>$alert </td>";
echo "<td>$accou nt</td>";
echo "<td>$lines 2[1]</td>";
echo "<td>$lines 2[4]</td>";
echo "<td>$lines 2[5]</td>";
echo "<td>$lines 2[6] $lines2[7]</td></tr>";
}
}
fclose($f);
?>[/PHP]
The match is being found fine but anything under the matched record is getting the same value of the variable when there is no match.
I tried if and elseif and i get the same problem this is the code i am using in the loop.
Could somebody help me please.
Basically i just want the $account variable to print only the matches which are correct.
[PHP]$fc=file("./jms/prod/log.txt");
//open same file and use "w" to clear file
$f=fopen("./jms/prod/log.txt","r");
//loop through array using foreach
foreach($fc as $line) {
$lines2 = preg_split('/\s+/', $line);
//echo "<tr><td>$lines 2[7]</td>";
if($lines2[5] > $msgcount) {
$t = "$lines2[5]";
if($t > 4 && $t < 100) {
$alert = '<span class="cream">W ARNING</span>';
}
if($t >= 100 && $t < 500) {
$alert = '<span class="yellow"> ALERT</span>';
}
if($t > 500 && $t < 1000) {
$alert = '<span class="orange"> ALERT - Over 500 msgs</span>';
}
if($t > 1000) {
$alert = '<span class="red">ALE RT - Over 1000 msgs</span>';
}
if($t > 10000) {
$alert = '<span class="red">URG ENT - Over 10000 msgs</span>';
}
if (preg_match("/^SBS.NA.EXCEPTI/", $lines2[1])) {
$account = '<span class="blue">Cl arify</span>';
}
if (preg_match("/^CL.ADAPT/", $lines2[1])) {
$account = '<span class="blue">Cl arify</span>';
}
if (preg_match("/^4499-C/", $lines2[1])) {
$account = '<span class="green">C larify2</span>';
}
if (preg_match("/ITG/", $lines2[1])) {
$account = '<span class="red">RPG </span>';
}
if (preg_match("/PRIMAVE/", $lines2[1])) {
$account = '<span class="blue">PR IMA</span>';
}
if (preg_match("/A.CRM.PAR/", $lines2[1])) {
$account = '<span class="green">c ompany1</span>';
}
if (preg_match("/CRM.PRODU/", $lines2[1])) {
$account = '<span class="green">c ompany1</span>';
}
if (preg_match("/NT.CONTRA/", $lines2[1])) {
$account = '<span class="green">c ompany2</span>';
}
if (preg_match("/NT.PRODU/", $lines2[1])) {
$account = '<span class="green">c ompany3</span>';
}
if (ereg("CRM.LOG$ ", $lines2[1])) {
$account = '<span class="green">C RM LOG</span>';
}
echo "<tr><td>$alert </td>";
echo "<td>$accou nt</td>";
echo "<td>$lines 2[1]</td>";
echo "<td>$lines 2[4]</td>";
echo "<td>$lines 2[5]</td>";
echo "<td>$lines 2[6] $lines2[7]</td></tr>";
}
}
fclose($f);
?>[/PHP]
Comment