469,282 Members | 1,758 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

compare strings echoing for wrong records

154 100+
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>$lines2[7]</td>";

if($lines2[5] > $msgcount) {
$t = "$lines2[5]";

if($t > 4 && $t < 100) {
$alert = '<span class="cream">WARNING</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">ALERT - Over 1000 msgs</span>';
}

if($t > 10000) {
$alert = '<span class="red">URGENT - Over 10000 msgs</span>';
}

if (preg_match("/^SBS.NA.EXCEPTI/", $lines2[1])) {
$account = '<span class="blue">Clarify</span>';
}

if (preg_match("/^CL.ADAPT/", $lines2[1])) {
$account = '<span class="blue">Clarify</span>';
}

if (preg_match("/^4499-C/", $lines2[1])) {
$account = '<span class="green">Clarify2</span>';
}


if (preg_match("/ITG/", $lines2[1])) {
$account = '<span class="red">RPG</span>';
}

if (preg_match("/PRIMAVE/", $lines2[1])) {
$account = '<span class="blue">PRIMA</span>';
}

if (preg_match("/A.CRM.PAR/", $lines2[1])) {
$account = '<span class="green">company1</span>';
}

if (preg_match("/CRM.PRODU/", $lines2[1])) {
$account = '<span class="green">company1</span>';
}

if (preg_match("/NT.CONTRA/", $lines2[1])) {
$account = '<span class="green">company2</span>';
}

if (preg_match("/NT.PRODU/", $lines2[1])) {
$account = '<span class="green">company3</span>';
}

if (ereg("CRM.LOG$", $lines2[1])) {
$account = '<span class="green">CRM LOG</span>';
}


echo "<tr><td>$alert</td>";
echo "<td>$account</td>";
echo "<td>$lines2[1]</td>";
echo "<td>$lines2[4]</td>";
echo "<td>$lines2[5]</td>";
echo "<td>$lines2[6] $lines2[7]</td></tr>";

}

}
fclose($f);
?>[/PHP]
Jun 18 '07 #1
2 1272
pbmods
5,821 Expert 4TB
Heya, jonathan184.

Expand|Select|Wrap|Line Numbers
  1. //open same file and use "w" to clear file
  2.  
  3. $f=fopen("./jms/prod/log.txt","r");
Did you mean...
Expand|Select|Wrap|Line Numbers
  1. $f=fopen("./jms/prod/log.txt","w");
  2.  
Give us an example of a string that is producing the wrong results; a well-placed continue might be able to fix your problem.
Jun 18 '07 #2
jonathan184
154 100+
Expand|Select|Wrap|Line Numbers
  1. $f=fopen("./jms/prod/log.txt","w");
  2.  
No i chose r i just wanted to read the file then parse and echo it, thats it basically.

Here is an example below, basically from the regular expression only one that should have CRM LOG in the column should be SBS.NA.CRM.LOG but as you can see the other records below are getting the same when they do not match

CRM LOG ------------------- SBS.NA.CRM.LOG
CRM LOG ------------------- SBS.NA.CRM.PEE.PEE.DEE.
CRM LOG ------------------- SBS.NA.CRM.ROLLER
CRM LOG ------------------- SBS.NA.DEE


How would i use the continue statement here?


Heya, jonathan184.



Did you mean...
Expand|Select|Wrap|Line Numbers
  1. $f=fopen("./jms/prod/log.txt","w");
  2.  
Give us an example of a string that is producing the wrong results; a well-placed continue might be able to fix your problem.
Jun 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by Stupid verifcation | last post: by
14 posts views Thread by Samuel R. Neff | last post: by
4 posts views Thread by Jim Langston | last post: by
11 posts views Thread by Marshall Dudley | last post: by
50 posts views Thread by titan nyquist | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.