title: PHP Undefined offset: 1
body: <p>Here's my PHP script:</p>
  
  <pre><code>    &lt;?php
  $address = htmlentities(strtolower(Config::get('aac.ip')));
  $port = Config::get('aac.port');
  
  @$sock = fsockopen ($address, $port, $errno, $errstr, 1);
  if(!$sock) echo '&lt;small class="muted"&gt;&lt;strong&gt;Server status:&lt;/strong&gt;&lt;/small&gt; &lt;span class="label label-important"&gt;OFFLINE&lt;/span&gt;&lt;br /&gt;'; else {
  $info = chr(6).chr(0).chr(255).chr(255).'info';
  fwrite($sock, $info);
  $data='';
  while (!feof($sock))$data .= fgets($sock, 1024);
  fclose($sock);
  
  // if needed
  // var_dump($data);
  
  
  preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches);
  $players = ''.$matches[1].' / '.$matches[2];
  preg_match('/uptime="(\d+)"/', $data, $matches);
  $h = floor($matches[1] / 3600);
  $m = floor(($matches[1] - $h*3600) / 60);
  $uptime = ''.$h.'h '.$m.'m';
  preg_match('/monsters total="(\d+)"/', $data, $matches); 
  $monsters = ''.$matches[1]; 
  preg_match('#&lt;motd&gt;(.*?)&lt;/motd&gt;#s', $data, $matches); 
  $motd = ''.$matches[1];
  preg_match('/npcs total="(\d+)"/', $data, $matches);
  $npcs = ''.$matches[1];
  
  if(empty($players) or $players == " / ") $players = "??? / ???";
  if(empty($uptime)) $uptime = "???";
  if(empty($monsters)) $monsters = "???";
  if(empty($motd)) $motd = "???"; 
  
  echo "
  &lt;small class='muted'&gt;&lt;strong&gt;Server status:&lt;/strong&gt;&lt;/small&gt; &lt;span class='label label-success'&gt;ONLINE&lt;/span&gt;&lt;br /&gt;
  &lt;small class='muted'&gt;&lt;strong&gt;Players:&lt;/strong&gt; $players&lt;/small&gt;&lt;br /&gt;
  &lt;small class='muted'&gt;&lt;strong&gt;Uptime:&lt;/strong&gt; $uptime&lt;/small&gt;&lt;br /&gt;
  &lt;small class='muted'&gt;&lt;strong&gt;Monsters:&lt;/strong&gt; $monsters&lt;/small&gt;&lt;br /&gt;
  &lt;small class='muted'&gt;&lt;strong&gt;MOTD:&lt;/strong&gt; $motd&lt;/small&gt;&lt;br /&gt;
  $npcs
  ";
  }
  
  ?&gt;
  </code></pre>
  
  <p>The <code>$npcs</code> variable returns an error <code>Undefined offset: 1</code>. I tried to solve it many ways, but none of them worked. Also, here's the var_dump of data:</p>
  
  <pre><code>    string '&lt;?xml version="1.0"?&gt;
  &lt;tsqp version="1.0"&gt;&lt;serverinfo uptime="33360" ip="127.0.0.1" servername="Forgotten" port="7171" location="Europe" url="http://otland.net/" server="The Forgotten Server" version="0.2.15" client="9.86"/&gt;&lt;owner name="" email="@otland.net"/&gt;&lt;players online="2" max="1000" peak="2"/&gt;&lt;monsters total="636"/&gt;&lt;map name="forgotten" author="Komic" width="1000" height="1000"/&gt;&lt;motd&gt;Welcome to the Forgotten Server!&lt;/motd&gt;&lt;/tsqp&gt;
  ' (length=442)
  </code></pre>
  
  <p>I'm trying to retrieve the info. Also, am I able to retrieve the servername, location, and things like that? I'm not experienced very much. :P</p>