Minequery PHP playerlist

Post here is you are having problems with any of the tutorials.
Post Reply
confuz3d
Posts: 2
Joined: Wed Jul 04, 2012 5:40 pm

Minequery PHP playerlist

Post by confuz3d »

Hey,

I followed the minequery PHP tutorial to make a status page for my minecraft server and everything works well except for 1 thing. The player names are displayed without any spaces and all on the same line.

What should i do if i wanted a <br /> between each names?

BTW here is the code i use to call the playerlist:
[syntax=php]
<font color='#ffa200'>Players: <br /><?php echo implode('', $info['playerList']);?></font>[/syntax]
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Minequery PHP playerlist

Post by Temor »

php.net is really useful if you're looking for information about a certain function. In this case the implode() function.
http://php.net/manual/en/function.implode.php

[syntax=text]string implode ( string $glue , array $pieces )[/syntax]

This means that the first parameter is the "glue", or whatever you want holding the words together to form a string. This could be anything. And the second parameter is the array of words you want to turn into a string.

[syntax=php]implode('<br />',$info['playerList']);[/syntax]

Easy as that.


/Edit:
Sidenote: You could loop through the names in the array and print them individually, instead of turning all of the names into a string.

[syntax=php]foreach($info['playerList'] as $name){
echo $name.'<br />';
}[/syntax]
confuz3d
Posts: 2
Joined: Wed Jul 04, 2012 5:40 pm

Re: Minequery PHP playerlist

Post by confuz3d »

Oh wow. you just openned my eyes! thank you for your time. :)
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Minequery PHP playerlist

Post by Temor »

You're welcome :)
Post Reply