Jump to content

sort output Teamspeak query


ozman

Recommended Posts

so lets say i got a small php that looks like this

yayaya i know its loose and porly scripted for now

 

Code:

<?php

$connection = fsockopen("IPADDRESS", TCP_PORT);

$output = fread($connection, 5);

echo $output;

echo "<BR />";

########################################

fputs($connection,"sel 9999\r\n");

$output = fread($connection, 5);

echo $output;

echo "<BR />";

########################################

fputs($connection,"pl\r\n");

$output = fread($connection, 2048);

echo $output;

echo "<BR />";

########################################

fputs($connection,"quit\r\n");

$output = fread($connection, 2048);

echo $output;

?>

the out put would be

 

[TS]

OK

p_id c_id ps bs pr br pl ping logintime idletime cprivs pprivs pflags ip nick loginname 38 26 129486 11309002 21241 1943352 39 291 65767 1 1 5 0 "0.0.0.0" "Smitty" "Smitty" 60 26 118192 11421617 2641 59451 53 90 56861 45006 0 4 0 "0.0.0.0" "S~K" "S~K" 99 26 19577 2406691 13222 2043780 2 85 5970 11 0 4 0 "0.0.0.0" "Hex" "Hex" 100 26 10417 1251833 6978 1076933 33 132 3362 0 0 0 0 "0.0.0.0" "fukknuckle" "" OK

 

this is one strate line of output wraped by the browser

 

how can i pull only p_id and nickname from the script so the output would be

 

[TS]

OK

p_id 38 nick Smitty

p_id 60 nick S~K

and so on

 

 

please help

Link to comment
https://forums.phpfreaks.com/topic/56422-sort-output-teamspeak-query/
Share on other sites

You can use the explode function, firstly to get the single line you want, and then to explode by spaces. You can then make use of the modulus operator.

 

<?php
$str = '[TS] 
OK 
p_id c_id ps bs pr br pl ping logintime idletime cprivs pprivs pflags ip nick loginname 38 26 129486 11309002 21241 1943352 39 291 65767 1 1 5 0 "0.0.0.0" "Smitty" "Smitty" 60 26 118192 11421617 2641 59451 53 90 56861 45006 0 4 0 "0.0.0.0" "S~K" "S~K" 99 26 19577 2406691 13222 2043780 2 85 5970 11 0 4 0 "0.0.0.0" "Hex" "Hex" 100 26 10417 1251833 6978 1076933 33 132 3362 0 0 0 0 "0.0.0.0" "fukknuckle" "" OK';
$lines = explode("\r\n",$str);//put each line in a separate part of the array $lines[2] contains the line we need.

$bits = explode(" ",$lines[2]);
for($i=0;$i<=count($bits);$i++){//generates two arrays containing the ids and nicknames
if(($i % 16==0) && $bits[$i] != 'OK'){
	$p_ids[] = $bits[$i];
}
if(($i - 14) % 16==0){
	$nicks[] = str_replace('"','',$bits[$i]);//get rid of quotes
}

}
echo $lines[0].'<br />'.$lines[1].'<br />';
for($i=1;$i<count($p_ids);$i++){//start at 1 because index 0 contains strings 'p_ids' and 'nicks respectively'
echo 'p_ids: '.$p_ids[$i].' nick: '.$nicks[$i].'<br />';
}
?>

 

This produced the following output:

 

[TS]

OK

p_ids: 38 nick: Smitty

p_ids: 60 nick: S~K

p_ids: 99 nick: Hex

p_ids: 100 nick: fukknuckle

<?php
$connection = fsockopen("IPADDRESS", TCP_PORT);
$output = fread($connection, 5);
echo $output;
echo "<BR />";
########################################
fputs($connection,"sel 9999\r\n");
$output = fread($connection, 5);
echo $output;
echo "<BR />";
########################################
fputs($connection,"pl\r\n");
$output = fread($connection, 2048);
echo $output;
echo "<BR />";
########################################

$str = $output;
$lines = explode("\r\n",$str);//put each line in a separate part of the array $lines[2] contains the line we need.

$bits = explode(" ",$lines[2]);
for($i=0;$i<=count($bits);$i++){//generates two arrays containing the ids and nicknames
if(($i % 16==0) && $bits[$i] != 'OK'){
	$p_ids[] = $bits[$i];
}
if(($i - 14) % 16==0){
	$nicks[] = str_replace('"','',$bits[$i]);//get rid of quotes
}

}
echo $lines[0].'<br />'.$lines[1].'<br />';
for($i=1;$i<count($p_ids);$i++){//start at 1 because index 0 contains strings 'p_ids' and 'nicks respectively'
echo 'p_ids: '.$p_ids[$i].' nick: '.$nicks[$i].'<br />';
}
?>

 

the out put is

 

[TS]

OK

p_id c_id ps bs pr br pl ping logintime idletime cprivs pprivs pflags ip nick loginname 112 26 65140 6639997 18246 1093440 27 87 18654 6460 0 4 0 "0.0.0.0" "S~K" "S~K" OK

p_id c_id ps bs pr br pl ping logintime idletime cprivs pprivs pflags ip nick loginname

112 26 65140 6639997 18246 1093440 27 87 18654 6460 0 4 0 "0.0.0.0" "S~K" "S~K"

Notice: Undefined variable: p_ids in /***/***/***/3.php on line 32

 

 

the origional works great but when i use the varable that produces the output i get this and dont know why

any body got idea i'm totaly lost why the output from the varable

$output is

[TS]

OK

p_id c_id ps bs pr br pl ping logintime idletime cprivs pprivs pflags ip nick loginname 38 26 129486 11309002 21241 1943352 39 291 65767 1 1 5 0 "0.0.0.0" "Smitty" "Smitty" 60 26 118192 11421617 2641 59451 53 90 56861 45006 0 4 0 "0.0.0.0" "S~K" "S~K" 99 26 19577 2406691 13222 2043780 2 85 5970 11 0 4 0 "0.0.0.0" "Hex" "Hex" 100 26 10417 1251833 6978 1076933 33 132 3362 0 0 0 0 "0.0.0.0" "fukknuckle" "" OK

 

post the same output to the sort part of the script and the output is ..

 

p_id c_id ps bs pr br pl ping logintime idletime cprivs pprivs pflags ip nick loginname

112 26 65140 6639997 18246 1093440 27 87 18654 6460 0 4 0 "0.0.0.0" "S~K" "S~K"

 

always the lowest p_id is displayed no more

 

almost there or start over ???????????????????

 

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.