compare strings echoing for wrong records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonathan184
    New Member
    • Nov 2006
    • 154

    #1

    compare strings echoing for wrong records

    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]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, jonathan184.

    Originally posted by jonathan184
    [code=php]//open same file and use "w" to clear file

    $f=fopen("./jms/prod/log.txt","r");[/code]
    Did you mean...
    [code=php]
    $f=fopen("./jms/prod/log.txt","w");
    [/code]

    Give us an example of a string that is producing the wrong results; a well-placed continue might be able to fix your problem.

    Comment

    • jonathan184
      New Member
      • Nov 2006
      • 154

      #3
      [code=php]
      $f=fopen("./jms/prod/log.txt","w");
      [/code]

      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.ROLL ER
      CRM LOG ------------------- SBS.NA.DEE


      How would i use the continue statement here?


      Originally posted by pbmods
      Heya, jonathan184.



      Did you mean...
      [code=php]
      $f=fopen("./jms/prod/log.txt","w");
      [/code]

      Give us an example of a string that is producing the wrong results; a well-placed continue might be able to fix your problem.

      Comment

      Working...