Need help reading file in an array and splitting using spaces

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

    Need help reading file in an array and splitting using spaces

    Hi I am trying to access a log file and read the fikle into an array and split the file using the space as a delimiter but i get this error.

    Parse error: syntax error, unexpected $end in D:\wamp\www\jms .php on line 87


    This is my code could somebody help me out please.
    [PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>test site</title>

    <link href="ais.css" rel="stylesheet " type="text/css" />
    </head>

    <body>
    <table width="100%" border="0">
    <tr>
    <td width="15%" height="56" valign="top"><i mg src="http://intranet.it-solutions.usa.s iemens.com/images/siemens_logo_FF FFFF.gif" alt="Siemens" width="128" height="54" /></td>
    <td width="42%" valign="top">&n bsp;</td>
    <td width="43%" valign="middle" >&nbsp;&nbsp;&n bsp;<span class="style1"> Application Integration Services Team Portal </span>&nbsp;&nbs p;&nbsp;</td>
    </tr>
    <tr>
    <td colspan="3" bgcolor="#66666 6">&nbsp;</td>
    </tr>
    <tr>
    <td height="79" bgcolor="#00003 3"><span class="leftnav" >Home</span><br />
    <br />
    <span class="leftnav" >TIBCO</span><br />
    <br />
    <span class="leftnav" >JMS</span><br />
    <br />
    <span class="leftnav" >Servers</span><br />
    <br /></td>
    <td colspan="2"><p> <strong><br />
    JMS</strong></p>
    <table width="70%" border="1">
    <tr>
    <th scope="col">Sta tus</th>
    <th scope="col">Tim e Stamp </th>
    <th scope="col">Que ue Name </th>
    <th scope="col">No. of Messages </th>
    <th scope="col">Siz e of Queue </th>
    </tr>
    <tr>

    <?PHP
    $msgcount = 10;

    //load file into $fc array

    $fc=file("log.t xt");


    $f=fopen("log.t xt","r");

    //loop through array using foreach

    foreach($fc as $line)
    {


    ?>
    $lines2 = explode($line, " ");

    <? if($lines2[4] > "$msgcount" ) {?>


    <td><? echo $line[0]; ?></td>
    <td><? echo $line[0]; ?></td>
    <td><? echo $line[0]; ?></td>
    <td><? echo $line[4]; ?></td>
    <td><? echo $line[5] \t $line[6]; ?></td>
    <? }

    }

    fclose($f);
    } ?>

    </tr>
    </table>
    <p><br />
    <br />
    </p></td>
    </tr>
    <tr>
    <td colspan="3" bgcolor="#CCCCC C">&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>[/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Originally posted by jonathan184
    [code=php]?>
    $lines2 = explode($line, " ");

    <?[/code]
    This line is outside any PHP code block. Is this intentional?

    Also, you use a long-format <?php tag once, but the others are short tags....

    Comment

    • jonathan184
      New Member
      • Nov 2006
      • 154

      #3
      No I forgot to put it within the block


      I did put it in the block this time and i still get the error. I had an extra curly bracket at the end and i took it off and i still have the same problem.

      Originally posted by pbmods
      This line is outside any PHP code block. Is this intentional?

      Also, you use a long-format <?php tag once, but the others are short tags....

      Comment

      • Purple
        Recognized Expert Contributor
        • May 2007
        • 404

        #4
        Hi

        I think the issue is in this block of code:

        [PHP]?>
        $lines2 = explode($line, " ");

        <? if($lines2[4] > "$msgcount" ) {?>


        <td><? echo $line[0]; ?></td>
        <td><? echo $line[0]; ?></td>
        <td><? echo $line[0]; ?></td>
        <td><? echo $line[4]; ?></td>
        <td><? echo $line[5] \t $line[6]; ?></td>
        <? }

        }

        fclose($f);
        } ?>[/PHP]

        line 11 has a \t in the middle, prob should read ."\t".

        Purple

        Comment

        • Purple
          Recognized Expert Contributor
          • May 2007
          • 404

          #5
          Hi,

          for completeness try this:

          [PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
          <title>test site</title>

          <link href="ais.css" rel="stylesheet " type="text/css" />
          </head>

          <body>
          <table width="100%" border="0">
          <tr>
          <td width="15%" height="56" valign="top"><i mg src="http://intranet.it-solutions.usa.s iemens.com/images/siemens_logo_FF FFFF.gif" alt="Siemens" width="128" height="54" /></td>
          <td width="42%" valign="top">&n bsp;</td>
          <td width="43%" valign="middle" >&nbsp;&nbsp;&n bsp;<span class="style1"> Application Integration Services Team Portal </span>&nbsp;&nbs p;&nbsp;</td>
          </tr>
          <tr>
          <td colspan="3" bgcolor="#66666 6">&nbsp;</td>
          </tr>
          <tr>
          <td height="79" bgcolor="#00003 3"><span class="leftnav" >Home</span><br />
          <br />
          <span class="leftnav" >TIBCO</span><br />
          <br />
          <span class="leftnav" >JMS</span><br />
          <br />
          <span class="leftnav" >Servers</span><br />
          <br /></td>
          <td colspan="2"><p> <strong><br />
          JMS</strong></p>
          <table width="70%" border="1">
          <tr>
          <th scope="col">Sta tus</th>
          <th scope="col">Tim e Stamp </th>
          <th scope="col">Que ue Name </th>
          <th scope="col">No. of Messages </th>
          <th scope="col">Siz e of Queue </th>
          </tr>
          <tr>

          <?PHP
          $msgcount = 10;

          //load file into $fc array

          $fc=file("log.t xt");


          $f=fopen("log.t xt","r");

          //loop through array using foreach

          foreach($fc as $line)
          {
          $lines2 = explode($line, " ");

          if($lines2[4] > "$msgcount" )
          {
          echo "<td>". $line[0] . "</td>";
          echo "<td>". $line[0]. "</td>";
          echo "<td>". $line[0]. "</td>";
          echo "<td>".$lin e[4]. "</td>";
          echo "<td>". $line[5] ."\t". $line[6]. "</td>";
          }
          }

          fclose($f);
          ?>

          </tr>
          </table>
          <p><br />
          <br />
          </p></td>
          </tr>
          <tr>
          <td colspan="3" bgcolor="#CCCCC C">&nbsp;</td>
          </tr>
          </table>
          </body>
          </html>[/PHP]

          Comment

          • Anthony2oo5
            New Member
            • Jun 2007
            • 26

            #6
            Your problem is on line 73,

            } ?>

            You opened a loop and an IF, then closed the IF and the loop, and have an extra close statement.

            Thats what is causing this error, but if you use purples code, he / she has fixed this along with a couple other mistakes.

            Comment

            Working...