Werte aus String rausholen.

Hallo
Frohe Ostern.

Da ich heute lange weile habe ich mal mit einer kleinen Teamspeack aplickation angefangen.

doch ich habe ein Problem mit dem auswerten von dem String den ich von der Telenet Konsole zurück bekomme.

der script sieht momentan so aus.

PHP:
<?php
//include blog


$fp = @fsockopen("localhost", 10011);
include './fuc.php';

$command['1'] = "login serveradmin jJBB+Rlg \n";
$command['2'] = "use sid=1 \n";
$command['3'] = "serverinfo \n";
$command['4'] = "servergrouplist \n";


//fwrite($fp,"serverinfo");
$schleife = true;
$i = 1;
$cmd = cmd($command[$i], $fp);


for ($i = 1; $i < 5; $i++) {



    if (strpos($cmd, "error id=0 msg=ok") === false) {
       
             echo nl2br(cmd($command[$i], $fp))."<br><br>";
             echo $command[$i]. "<br>";
            echo '<br><br>';
            if($i == 4)
            {
               echo nl2br(cmd($command[$i], $fp))."<br><br>"; 
            }  else {
                
            }

    } else {
        
        $schleife = false;
        break;


        
    }
}
fclose($fp);
?>

func.php
PHP:
<?php

function cmd($command, $fp){
    fputs($fp, "$command");
    $cmd = fread($fp, 8096);
    
    return $cmd;
    
}
?>

so weit funktioniert auch alles aber ich bin nun an einen Punkt angekommen wo ich damals schon probs hatte und zwar bekomme ich einnen Risigen String zurück wo ich nach gewissen werten suchen muss und die werte nach diesem wert brauche z.B

Code:
virtualserver_unique_identifier=Z3zi9CySLidmLwgpwMYgCi0buiw=virtualserver_name=TeamSpeak\s]I[\sServervirtualserver_welcomemessage=Welcome\sto\sTeamSpeak,\scheck\swww.teamspeak.com\sfor\slatest\sinformation virtualserver_platform=Windows virtualserver_version=3.0.6.1\s[Build:\s1340956745] virtualserver_maxclients=32 virtualserver_password virtualserver_clientsonline=2 virtualserver_channelsonline=2 virtualserver_created=1364586031 virtualserver_uptime=15247 virtualserver_codec_encryption_mode=0 virtualserver_hostmessage virtualserver_hostmessage_mode=0 virtualserver_filebase=files\\virtualserver_1 virtualserver_default_server_group=8 virtualserver_default_channel_group=8 virtualserver_flag_password=0 virtualserver_default_channel_admin_group=5 virtualserver_max_download_total_bandwidth=18446744073709551615 virtualserver_max_upload_total_bandwidth=18446744073709551615 virtualserver_hostbanner_url virtualserver_hostbanner_gfx_url virtualserver_hostbanner_gfx_interval=0 virtualserver_complain_autoban_count=5 virtualserver_complain_autoban_time=1200 virtualserver_complain_remove_time=3600 virtualserver_min_clients_in_channel_before_forced_silence=100 virtualserver_priority_speaker_dimm_modificator=-18.0000 virtualserver_id=1 virtualserver_antiflood_points_tick_reduce=5 virtualserver_antiflood_points_needed_command_block=150 virtualserver_antiflood_points_needed_ip_block=250 virtualserver_client_connections=1 virtualserver_query_client_connections=86 virtualserver_hostbutton_tooltip virtualserver_hostbutton_url virtualserver_hostbutton_gfx_url virtualserver_queryclientsonline=1 virtualserver_download_quota=18446744073709551615 virtualserver_upload_quota=18446744073709551615 virtualserver_month_bytes_downloaded=0 virtualserver_month_bytes_uploaded=0 virtualserver_total_bytes_downloaded=0 virtualserver_total_bytes_uploaded=0 virtualserver_port=9987 virtualserver_autostart=1 virtualserver_machine_id virtualserver_needed_identity_security_level=8 virtualserver_log_client=0 virtualserver_log_query=0 virtualserver_log_channel=0 virtualserver_log_permissions=1 virtualserver_log_server=0 virtualserver_log_filetransfer=0 virtualserver_min_client_version=12369 virtualserver_name_phonetic virtualserver_icon_id=0 virtualserver_reserved_slots=0 virtualserver_total_packetloss_speech=0.0000 virtualserver_total_packetloss_keepalive=0.0000 virtualserver_total_packetloss_control=0.0000 virtualserver_total_packetloss_total=0.0000 virtualserver_total_ping=0.0000 virtualserver_ip virtualserver_weblist_enabled=1 virtualserver_ask_for_privilegekey=0 virtualserver_hostbanner_mode=0 virtualserver_status=online connection_filetransfer_bandwidth_sent=0 connection_filetransfer_bandwidth_received=0 connection_filetransfer_bytes_sent_total=0 connection_filetransfer_bytes_received_total=0 connection_packets_sent_speech=0 connection_bytes_sent_speech=0 connection_packets_received_speech=644 connection_bytes_received_speech=68844 connection_packets_sent_keepalive=2993 connection_bytes_sent_keepalive=122713 connection_packets_received_keepalive=2993 connection_bytes_received_keepalive=125705 connection_packets_sent_control=92 connection_bytes_sent_control=20562 connection_packets_received_control=92 connection_bytes_received_control=10721 connection_packets_sent_total=3085 connection_bytes_sent_total=143275 connection_packets_received_total=3729 connection_bytes_received_total=205270 connection_bandwidth_sent_last_second_total=81 connection_bandwidth_sent_last_minute_total=83 connection_bandwidth_received_last_second_total=83 connection_bandwidth_received_last_minute_total=88

so
Nach diesem wert muss ich das String durchsuchen
mit diesem wert muss ich arbeiten also in eine Variable speichern
so das muss ich mit mehreren angaben machen in diesem String ich habe aber keinen Schimmer wie ich das anstelle.
ich weiß nur das ich denke ich mal mit explode arbeiten muss aber habe auch nichts im Inet gefunden.


Danke für eure hilfe im Vorraus.
 
Hi,

schau mal, ob dir das was bringt:

PHP:
<?php
$s = <<<EOT
virtualserver_unique_identifier=Z3zi9CySLidmLwgpwMYgCi0buiw= virtualserver_name=TeamSpeak\s]I[\sServer virtualserver_welcomemessage=Welcome\sto\sTeamSpeak,\scheck\s[URL]www.teamspeak.com[\/URL]\sfor\slatest\sinformation virtualserver_platform=Windows virtualserver_version=3.0.6.1\s[Build:\s1340956745] virtualserver_maxclients=32 virtualserver_password virtualserver_clientsonline=2 virtualserver_channelsonline=2 virtualserver_created=1364586031 virtualserver_uptime=15247 virtualserver_codec_encryption_mode=0 virtualserver_hostmessage virtualserver_hostmessage_mode=0 virtualserver_filebase=files\\virtualserver_1 virtualserver_default_server_group=8 virtualserver_default_channel_group=8 virtualserver_flag_password=0 virtualserver_default_channel_admin_group=5 virtualserver_max_download_total_bandwidth=18446744073709551615 virtualserver_max_upload_total_bandwidth=18446744073709551615 virtualserver_hostbanner_url virtualserver_hostbanner_gfx_url virtualserver_hostbanner_gfx_interval=0 virtualserver_complain_autoban_count=5 virtualserver_complain_autoban_time=1200 virtualserver_complain_remove_time=3600 virtualserver_min_clients_in_channel_before_forced_silence=100 virtualserver_priority_speaker_dimm_modificator=-18.0000 virtualserver_id=1 virtualserver_antiflood_points_tick_reduce=5 virtualserver_antiflood_points_needed_command_block=150 virtualserver_antiflood_points_needed_ip_block=250 virtualserver_client_connections=1 virtualserver_query_client_connections=86 virtualserver_hostbutton_tooltip virtualserver_hostbutton_url virtualserver_hostbutton_gfx_url virtualserver_queryclientsonline=1 virtualserver_download_quota=18446744073709551615 virtualserver_upload_quota=18446744073709551615 virtualserver_month_bytes_downloaded=0 virtualserver_month_bytes_uploaded=0 virtualserver_total_bytes_downloaded=0 virtualserver_total_bytes_uploaded=0 virtualserver_port=9987 virtualserver_autostart=1 virtualserver_machine_id virtualserver_needed_identity_security_level=8 virtualserver_log_client=0 virtualserver_log_query=0 virtualserver_log_channel=0 virtualserver_log_permissions=1 virtualserver_log_server=0 virtualserver_log_filetransfer=0 virtualserver_min_client_version=12369 virtualserver_name_phonetic virtualserver_icon_id=0 virtualserver_reserved_slots=0 virtualserver_total_packetloss_speech=0.0000 virtualserver_total_packetloss_keepalive=0.0000 virtualserver_total_packetloss_control=0.0000 virtualserver_total_packetloss_total=0.0000 virtualserver_total_ping=0.0000 virtualserver_ip virtualserver_weblist_enabled=1 virtualserver_ask_for_privilegekey=0 virtualserver_hostbanner_mode=0 virtualserver_status=online connection_filetransfer_bandwidth_sent=0 connection_filetransfer_bandwidth_received=0 connection_filetransfer_bytes_sent_total=0 connection_filetransfer_bytes_received_total=0 connection_packets_sent_speech=0 connection_bytes_sent_speech=0 connection_packets_received_speech=644 connection_bytes_received_speech=68844 connection_packets_sent_keepalive=2993 connection_bytes_sent_keepalive=122713 connection_packets_received_keepalive=2993 connection_bytes_received_keepalive=125705 connection_packets_sent_control=92 connection_bytes_sent_control=20562 connection_packets_received_control=92 connection_bytes_received_control=10721 connection_packets_sent_total=3085 connection_bytes_sent_total=143275 connection_packets_received_total=3729 connection_bytes_received_total=205270 connection_bandwidth_sent_last_second_total=81 connection_bandwidth_sent_last_minute_total=83 connection_bandwidth_received_last_second_total=83 connection_bandwidth_received_last_minute_total=88 
EOT;

$key_values = preg_split('/ /', $s);

//var_dump($key_values);

foreach($key_values as $key_value)
{
  $kvs = preg_split('/\=/', $key_value);
  //var_dump($kvs);
  //echo "$key = '$value'";
  
  if($kvs[0] == 'virtualserver_name')
  {
    echo "$kvs[0] = $kvs[1]";
  }
}
 
JA würde es aber habe mir ne lösung gebastelt nun sieht es so aus

PHP:
<?php

//include blog


$fp = @fsockopen("localhost", 10011);
include './fuc.php';

$command['1'] = "login serveradmin jJBB+Rlg \n";
$command['2'] = "use sid=1 \n";
$command['3'] = "serverinfo \n";
$command['4'] = "servergrouplist \n";


//fwrite($fp,"serverinfo");
$schleife = true;
$i = 1;
cmd($command[$i], $fp);


/* while ($schleife == true) {


  echo $cmd = cmd("serverinfo \n", $fp);

  if (strpos($cmd, "error id=0 msg=ok") === false) {


  } else {

  $schleife = false;
  break;



  }
  } */

fputs($fp, "serverinfo \n");
$ende = true;
while ($ende == true) {
    $cmd = fread($fp, 8014);
    if (strpos($cmd, "error id=0 msg=ok") === false) {
        $ende = false;

        break;
    } else {
        $ende = true;
    }
}

$explo = explode(" ", $cmd);

$servername = explode("=", $explo['1']);
echo $servername['1'];

fputs($fp, "channellist");


fclose($fp);
?>

leertastejn werden mit \s dargestelt dewegen funktioniert das mit explode(" ", $string) ganz gut

was nur etwas lästig ist das ich immer schleifen machen muss um den kram auszugeben geht dasu auch anders ?
 
Zuletzt bearbeitet:
Zurück