Jump to content

Array ( ) Showing on webpage


jkewlo

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/225355-array-showing-on-webpage/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.