I just started using php and really have hardly any idea what I'm doing... but i am getting unexpected $end and I am clearly over seeing something... please help!

Code:
<?php

include('mc/init.inc.php');

$info = fetch_server_info($config['server']['ip'], $config['server']['port']);

?>

<html>
<head>
   <title><?php echo $config['server']['ip'] ?></title>
</head>
<body>
   
   <h1><?php echo $config ['server']['ip'] ?></h1>
   
   <?php
   
   if ($info === false){
   ?>
      <p>
         Status: Offline
      </p>
      <?php
   } else {
      ?>
      <p>
         Status: Online
      </p>
      <p>
         Slots: <?php echo $info['playerCount']; ?> / <?php echo $info['maxPlayers'] ?>;
      </p>
      <p>
         Players Online: <?php echo implode(', ', $info['playerList']); ?>
      </p>
   }

</body>
</html>
[/code]
You're missing <? php ... ?> tags around the closing } brace in the if/else statement. The unexpected $end means that it reached the end of the document before all of the opened braces in the script were closed.
So it should be like:

<?php
}
?>
Yes, but something like this would be even better:


Code:
<?php

include('mc/init.inc.php');

$info = fetch_server_info($config['server']['ip'], $config['server']['port']);

?>

<html>
<head>
   <title><?php echo $config['server']['ip'] ?></title>
</head>
<body>
   
   <h1><?php echo $config ['server']['ip'] ?></h1>
   
   <?php
   
   if ($info === false){
      echo '<p>Status: Offline</p>';
   } else {
      echo '<p>Status: Online</p>';
      echo '<p>Slots: '.$info['playerCount'].'/'.$info['maxPlayers'].'</p>';
      echo '<p>Players Online: '.implode(', ', $info['playerList']).'</p>';
   }
   ?>

</body>
</html>
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement