Hello. First of all, i’m new here, and im hoping someone could point out the problem with my code.
What im trying to do is, get the Online players names & titles from a game server and display their name and title. The data gets pulled from the server perfectly fine, but what im stumped on is having the data go into an array or table of some sort.
Heres what the output looks like right now.
a:55:{i:0;a:5:{s:4:"name";s:7:"legendl";s:5:"title";s:12:"iluhshuga<3!";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:0:"";}i:1;a:5:{s:4:"name";s:10:"eagleblade";s:5:"title";s:10:"Soars High";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"DEW";}i:2;a:5:{s:4:"name";s:11:"brainwashed";s:5:"title";s:8:"Taylored";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"IL";}i:3;a:5:{s:4:"name";s:6:"beckah";s:5:"title";s:10:"wootage <3";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"DEW";}i:4;a:5:{s:4:"name";s:5:"liams";s:5:"title";s:5:"Liams";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"NM";}i:5;a:5:{s:4:"name";s:9:"pooterman";s:5:"title";s:7:"First 9";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"SOA";}i:6;a:5:{s:4:"name";s:8:"storchyx";s:5:"title";s:7:"ThaWunn";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:0:"";}i:7;a:5:{s:4:"name";s:12:"boredomrawrz";s:5:"title";s:20:"your love is my love";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:0:"";}i:8;a:5:{s:4:"name";s:12:"angelofdeath";s:5:"title";s:16:"I <333 Jimmy!!(:";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"GA";}i:9;a:5:{s:4:"name";s:6:"azulna";s:5:"title";s:8:"bluelady";s:5:"admin";b:0;s:5:"class";i:2;s:5:"guild";s:3:"GUN";}i:10;a:5:{s:4:"name";s:5:"sxpty";s:5:"title";s:6:"Try me";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"SAX";}i:11;a:5:{s:4:"name";s:4:"nath";s:5:"title";s:17:"He who dares wins";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"NU";}i:12;a:5:{s:4:"name";s:8:"jdweyant";s:5:"title";s:9:"Deception";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"GA";}i:13;a:5:{s:4:"name";s:8:"danielle";s:5:"title";s:13:"I Miss You Ken";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"SOW";}i:36;a:5:{s:4:"name";s:8:"deadwish";s:5:"title";s:9:"Hockey 18";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"AD";}i:37;a:5:{s:4:"name";s:11:"welshknight";s:5:"title";s:20:"R.I.P Ladypixiecat<3";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"NM";}i:38;a:5:{s:4:"name";s:7:"tinaman";s:5:"title";s:15:"I come in peace";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"SOW";}i:39;a:5:{s:4:"name";s:7:"melodee";s:5:"title";s:0:"";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:0:"";}i:40;a:5:{s:4:"name";s:5:"mzmay";s:5:"title";s:8:"Gemini<3";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"GA";}i:41;a:5:{s:4:"name";s:9:"redbarbie";s:5:"title";s:0:"";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"DEW";}i:42;a:5:{s:4:"name";s:10:"desolution";s:5:"title";s:8:"Trololol";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"GA";}i:43;a:5:{s:4:"name";s:7:"iolpimp";s:5:"title";s:10:"The expert";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:0:"";}i:44;a:5:{s:4:"name";s:7:"brebear";s:5:"title";s:13:"R.I.P Candace";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"NM";}i:45;a:5:{s:4:"name";s:9:"malicious";s:5:"title";s:8:"Darkness";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"GA";}i:46;a:5:{s:4:"name";s:7:"beleren";s:5:"title";s:9:"Scarecrow";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:0:"";}i:47;a:5:{s:4:"name";s:4:"xion";s:5:"title";s:13:"I'm Green Man";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"GA";}i:48;a:5:{s:4:"name";s:4:"paul";s:5:"title";s:17:"Forever Ping's <3";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"NU";}i:49;a:5:{s:4:"name";s:6:"lilaxx";s:5:"title";s:0:"";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:2:"SO";}i:50;a:5:{s:4:"name";s:4:"jono";s:5:"title";s:3:"God";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:0:"";}i:51;a:5:{s:4:"name";s:11:"oreodelight";s:5:"title";s:12:"Love is Evol";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"SUN";}i:52;a:5:{s:4:"name";s:11:"thawindiigo";s:5:"title";s:7:"WINDIGO";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:0:"";}i:53;a:5:{s:4:"name";s:4:"rooy";s:5:"title";s:13:"Demonic Angel";s:5:"admin";b:0;s:5:"class";i:1;s:5:"guild";s:0:"";}i:54;a:5:{s:4:"name";s:8:"kiraevol";s:5:"title";s:19:"<3Goddess of Hell<3";s:5:"admin";b:0;s:5:"class";i:6;s:5:"guild";s:3:"LTF";}}
And heres the following code;
[php]<?PHP
$serverhost = “**";
$serverport = "”;
function Number($b1, $b2 = 254, $b3 = 254, $b4 = 254)
{
if ($b1 == 0 || $b1 == 254) $b1 = 1;
if ($b2 == 0 || $b2 == 254) $b2 = 1;
if ($b3 == 0 || $b3 == 254) $b3 = 1;
if ($b4 == 0 || $b4 == 254) $b4 = 1;
--$b1;
--$b2;
--$b3;
--$b4;
return ($b4*16194277 + $b3*64009 + $b2*253 + $b1);
}
function GetOnlineNewbs($serverhost, $serverport)
{
$serverconn = @fsockopen($serverhost, $serverport, $errno, $errstr, 0.5);
$online = (bool)$serverconn;
$onlinelist = array();
if ($online)
{
$request_online = chr(5).chr(254).chr(1).chr(22).chr(254).chr(255);
fwrite($serverconn, $request_online);
$raw = fread($serverconn, 1024*256); // Read up to 256KB of data
fclose($serverconn);
$raw = substr($raw, 5); // length, ID, replycode
$chars = Number(ord($raw[0]), ord($raw[1])); $raw = substr($raw, 2); // Number of characters
$raw = substr($raw, 1); // separator
for ($i = 0; $i < $chars; ++$i)
{
$newchar = array(
‘name’ => ‘’,
‘title’ => ‘’,
‘admin’ => ‘’,
‘class’ => ‘’,
‘guild’ => ‘’,
);
$pos = strpos($raw, chr(255));
$newchar['name'] = substr($raw, 0, $pos);
$raw = substr($raw, $pos+1);
$pos = strpos($raw, chr(255));
$newchar['title'] = substr($raw, 0, $pos);
$raw = substr($raw, $pos+1);
$raw = substr($raw, 1); // ?
$newchar['admin'] = Number(ord(substr($raw, 0, 1)));
$newchar['admin'] = ($newchar['admin'] == 4 || $newchar['admin'] == 5 || $newchar['admin'] == 9 || $newchar['admin'] == 10);
$raw = substr($raw, 1);
$newchar['class'] = Number(ord(substr($raw, 0, 1)));
$raw = substr($raw, 1);
$newchar['guild'] = trim(substr($raw, 0, 3));
$raw = substr($raw, 3);
$raw = substr($raw, 1); // separator
$onlinelist[] = $newchar;
}
ksort($onlinelist);
//echo unserialize($list);
echo serialize($onlinelist);
}
else
{
echo "<h3 style='font-size: 30px'>EE Is Offline =o</h3>";
}
}
echo GetOnlineNewbs($serverhost, $serverport);
?> [/php]
Could someone let me know what im doing wrong? lol