ozman Posted June 20, 2007 Share Posted June 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56422-sort-output-teamspeak-query/ Share on other sites More sharing options...
GingerRobot Posted June 20, 2007 Share Posted June 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56422-sort-output-teamspeak-query/#findComment-278668 Share on other sites More sharing options...
ozman Posted June 20, 2007 Author Share Posted June 20, 2007 Thank You Very Much Quote Link to comment https://forums.phpfreaks.com/topic/56422-sort-output-teamspeak-query/#findComment-278683 Share on other sites More sharing options...
ozman Posted June 21, 2007 Author Share Posted June 21, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/56422-sort-output-teamspeak-query/#findComment-279055 Share on other sites More sharing options...
ozman Posted June 21, 2007 Author Share Posted June 21, 2007 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 ??????????????????? Quote Link to comment https://forums.phpfreaks.com/topic/56422-sort-output-teamspeak-query/#findComment-279419 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.