string splitten (Opgelost)
Sander1993 - 30/12/2008 16:58 (laatste wijziging 30/12/2008 16:58)
PHP interesse
hey,
ik heb deze string:
0
5418 102 "[=ST=]Flo92Will"
3932 95 "[=ST=]arnaud"
600 166 "[=ST=]TYLER1012"
3022 96 "PRZmop"
6004 103 "Boczo_PL"
1502 111 "[=ST=]Trak"
0 155 "Master_pt"
8 316 "[=ST=]STpeanut"
2400 114 "[RfF]KarOo"
1532 131 "Kondzi1993pl"
4508 108 "[RfF]YourFather"
1808 122 "Wanted31"
1200 87 "Federlun"
5416 93 "[=ST=]juliendu18"
614 205 "tompson_hero"
600 121 "dogto-28"
308 145 "razorbackman"
0 135 "Kris7_PL"
908 146 "EvilMonkeyN"
2708 107 "PieceOfCake"
604 173 "Aqq_PL"
1208 161 "Pflanz35"
de nul bovenaan kan verschillen van waarde, nu wil ik dit:
0
en dit:
5418 102 "[=ST=]Flo92Will"
3932 95 "[=ST=]arnaud"
600 166 "[=ST=]TYLER1012"
3022 96 "PRZmop"
6004 103 "Boczo_PL"
1502 111 "[=ST=]Trak"
0 155 "Master_pt"
8 316 "[=ST=]STpeanut"
2400 114 "[RfF]KarOo"
1532 131 "Kondzi1993pl"
4508 108 "[RfF]YourFather"
1808 122 "Wanted31"
1200 87 "Federlun"
5416 93 "[=ST=]juliendu18"
614 205 "tompson_hero"
600 121 "dogto-28"
308 145 "razorbackman"
0 135 "Kris7_PL"
908 146 "EvilMonkeyN"
2708 107 "PieceOfCake"
604 173 "Aqq_PL"
1208 161 "Pflanz35"
van elkaar splitten, hoe doe ik dat
btw, dit is de bijbehorende code
<?php
$fp = fsockopen("udp://193.253.226.181", 28960, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fwrite($fp, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0XFF) . chr(0x67) . chr(0x65) . chr(0x74) . chr(0x73) . chr(0x74) . chr(0x61) . chr(0x74) . chr(0x75) . chr(0x73));
$alldata = stream_get_meta_data($fp);
$ServerData = fread($fp, 4096);
list(,,$admin,,$mail,,$irc,,$website,,$fx,,$compass,,$gametype,,$game,,$map,,$penetrationCount,,$protocol,,$watersim,,$shortversion,,$allowAnonymous,,$disableClientConsole,,$floodprotect,,$hostname,,$maxclients,,$maxPing,,$maxRate,,$minPing,,$privateClients,,$punkbuster,,$pure,,$voice,,$ui_maxclients,,$pswrd,,$modandplayers) = explode('\\',$ServerData);
list($mod,$players) = explode('\r\n',$modandplayers); //dit gaat dus niet
echo $mod."<br><br><br>";
echo nl2br($ServerData);
}
?>
<?php
$fp = fsockopen ( "udp://193.253.226.181" , 28960 , $errno , $errstr , 30 ) ; if ( ! $fp ) {
echo "$errstr ($errno )<br />\n " ; } else {
$ServerData = fread ( $fp , 4096 ) ; list ( ,, $admin ,, $mail ,, $irc ,, $website ,, $fx ,, $compass ,, $gametype ,, $game ,, $map ,, $penetrationCount ,, $protocol ,, $watersim ,, $shortversion ,, $allowAnonymous ,, $disableClientConsole ,, $floodprotect ,, $hostname ,, $maxclients ,, $maxPing ,, $maxRate ,, $minPing ,, $privateClients ,, $punkbuster ,, $pure ,, $voice ,, $ui_maxclients ,, $pswrd ,, $modandplayers ) = explode ( '\\' , $ServerData ) ; list ( $mod , $players ) = explode ( '\r\n' , $modandplayers ) ; //dit gaat dus niet echo $mod . "<br><br><br>" ; }
?>
3 antwoorden
Gesponsorde links
Martijn - 30/12/2008 17:04 (laatste wijziging 30/12/2008 17:05)
Crew PHP
eerst explode je het op \r\n, en dan een foreach loopje, regel 1 doe je mee wat je dr mee wilt, en alle regels daarna zijn al je users waar je die info met een explode op spatie mee kan delen
Koen - 30/12/2008 17:15
PHP expert
<?php
$fp = fsockopen("udp://193.253.226.181", 28960, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fwrite($fp, chr(0xFF) . chr(0xFF) . chr(0xFF) . chr(0XFF) . chr(0x67) . chr(0x65) . chr(0x74) . chr(0x73) . chr(0x74) . chr(0x61) . chr(0x74) . chr(0x75) . chr(0x73));
$alldata = stream_get_meta_data($fp);
$ServerData = fread($fp, 4096);
list(,,$admin,,$mail,,$irc,,$website,,$fx,,$compass,,$gametype,,$game,,$map,,$penetrationCount,,$protocol,,$watersim,,$shortversion,,$allowAnonymous,,$disableClientConsole,,$floodprotect,,$hostname,,$maxclients,,$maxPing,,$maxRate,,$minPing,,$privateClients,,$punkbuster,,$pure,,$voice,,$ui_maxclients,,$pswrd,,$modandplayers) = explode('\\',$ServerData);
$aArray = explode("\n",$modandplayers);
$mod = $aArray[0];
$aArray = array_diff($aArray, array($aArray[0]));
$players = implode("\n", $aArray);
echo $mod."<br><br><br>";
echo $players."<br><br><br>";
}
?>
<?php
$fp = fsockopen ( "udp://193.253.226.181" , 28960 , $errno , $errstr , 30 ) ; if ( ! $fp ) {
echo "$errstr ($errno )<br />\n " ; } else {
$ServerData = fread ( $fp , 4096 ) ; list ( ,, $admin ,, $mail ,, $irc ,, $website ,, $fx ,, $compass ,, $gametype ,, $game ,, $map ,, $penetrationCount ,, $protocol ,, $watersim ,, $shortversion ,, $allowAnonymous ,, $disableClientConsole ,, $floodprotect ,, $hostname ,, $maxclients ,, $maxPing ,, $maxRate ,, $minPing ,, $privateClients ,, $punkbuster ,, $pure ,, $voice ,, $ui_maxclients ,, $pswrd ,, $modandplayers ) = explode ( '\\' , $ServerData ) ; $aArray = explode ( "\n " , $modandplayers ) ; $mod = $aArray [ 0 ] ;
echo $mod . "<br><br><br>" ; echo $players . "<br><br><br>" ; }
?>
Gesponsorde links
Dit onderwerp is gesloten .