jkewlo Posted January 23, 2011 Share Posted January 23, 2011 Hello, I got a simple script to show how many user's are online for a game. It is showing the user's but in a ARRAY like this Array ( [0] => Rchsingram34 [1] => killgorekiller [2] => jasonry25 [3] => suburbanite09 [4] => Torn2010 [5] => Xacktar [6] => The5thExotic [7] => Pledgemonkey [8] => Mystikilla [9] => luge [10] => tbtregenza [11] => dffidel [12] => xaanit [13] => mrxCIC [14] => vobilli [15] => cyberbullet [16] => porkycain [17] => Doombringer721 [18] => Ishaye [19] => CkGordon [20] => Mahngiel [21] => dj_de1337ed ) Here is my code <?php define("NL", "\n"); class Minequery { function __construct($server, $port = 25566) { $this->socket = fsockopen($server, $port, $erno, $erst, 5); if ($this->socket == FALSE) { trigger_error("Could not connect to the remote server", E_USER_ERROR); die(); } else { $this->query(); } } private function query() { $query = "QUERY\n"; $buffer = ""; fwrite($this->socket, $query); while (!feof($this->socket)) { $buffer .= fgets($this->socket, 1024); } $this->query = explode("\n", $buffer); } public function port() { $port = explode(' ', $this->query[0]); return $port[1]; } public function player_count() { $count = explode(' ', $this->query[1]); return $count[1]; } public function max_players() { $max = explode(' ', $this->query[2]); return $max[1]; } public function player_list() { $list = explode(' ', $this->query[3], 2 ); $list = trim($list[1], '[]'); $list = explode(',', $list); foreach ($list as $player) { $player_list[] = trim($player); } return $player_list; } } ?> and the useage is pretty simple print_r($status->player_list()); but I cant for the life of me not get it to print Array ( ) I would like to just get the user names without Array and the Array numbers to it.. any help would be great. Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 23, 2011 Share Posted January 23, 2011 don't use print_r, simply loop thru the array Quote Link to comment Share on other sites More sharing options...
jkewlo Posted January 23, 2011 Author Share Posted January 23, 2011 Thats the thing. I am not good with array's so how would I do that?? Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted January 23, 2011 Share Posted January 23, 2011 $playerList = $status->player_list(); echo implode(", ", $playerList); Try the above code, tell me if works or not Regards, PaulRyan. Quote Link to comment Share on other sites More sharing options...
jkewlo Posted January 23, 2011 Author Share Posted January 23, 2011 I feel really noob I have not touched any code in a while so excuse me for being a dumbass lol IDK where to put your code PaulRyan, I put it in the foreach loop with no luck Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 23, 2011 Share Posted January 23, 2011 wherever you had the print_r is where you would put his code Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted January 23, 2011 Share Posted January 23, 2011 My bad, I forgot to say that...thanks Litebearer Quote Link to comment Share on other sites More sharing options...
jkewlo Posted January 23, 2011 Author Share Posted January 23, 2011 Thank you guys very much!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.