nickkarma Posted September 30, 2007 Share Posted September 30, 2007 Fairly new to PHP and I basically have a string that will be loaded with information that I need to somehow get into an array or something so I can more easily call on it to work with in my script. The example output I have is hostname: Insomnia TF2 Server version : 1.0.0.2/9 3247 secure udp/ip : 66.150.155.81:27015 map : cp_gravelpit at: 0 x, 0 y, 0 z players : 17 (24 max) # userid name uniqueid connected ping loss state adr # 368 "pumpkinaza" STEAM_0:1:16339968 38:20 62 0 active 72.111.52:27005 # 352 "zhr^sm0kez" STEAM_0:0:13942862 1:22:03 58 0 active 68.91.92:33561 # 373 "Revant" STEAM_0:1:4151980 25:38 85 0 active 66.1.91:27005 # 338 "zhr^Shaun Alexander" STEAM_0:0:12899953 2:32:39 81 0 active 24.19.145:27005 # 378 "parnell555" STEAM_0:1:16210038 20:35 102 0 active 66.91.44:27005 # 377 "Rogg" STEAM_0:0:4644486 22:43 51 0 active 63.81.36:37135 # 366 "Choplol" STEAM_0:0:16285278 42:26 61 0 active 72.42.253:8331 # 360 "[unknown]" STEAM_0:0:7771895 56:36 187 0 active 211.247.75:27005 # 318 "Theone" STEAM_0:1:60380 3:43:25 89 0 active 98.106.239:43620 # 365 "Tide" STEAM_0:1:11566164 42:44 73 0 active 71.0.40:27005 # 381 "sollars" STEAM_0:1:3918650 14:02 215 0 active 81.71.199:51605 # 367 "frost" STEAM_0:0:4621907 42:04 73 0 active 66.38.89:61420 # 386 "zhr^dangerdoom" STEAM_0:0:4069842 05:00 70 0 active 71.25.201:50630 # 372 "Archangel" STEAM_0:0:6785933 28:09 116 0 active 70.255.75:27005 # 375 "the.g.chan" STEAM_0:0:16174051 25:25 32 0 active 169.117.77:27005 # 315 "iNs|Quasar" STEAM_0:1:16228721 4:00:10 88 0 active 68.128.133:9328 # 380 "Corporal_Tunnel" STEAM_0:0:13441685 15:56 105 0 active 69.162.211:60060 Took a set of #'s out of the IP's. Anyways to give an idea of what what I'm trying to get out is like "hostname:" $hostname = "Insomnia TF2 Server", $ip = "66.150.155.81:27015", $curplayers = 17, $maxplayers = 24 and such up until the first 2nd "#" which starts listing the player name and information that would be nice to somehow form into like an array $player[0]['id'], $player[0]['name'], etc. Now I really don't know where to get it going, I was thinking of trying to use explode() with the # sign then further breaking stuff down individually but before doing that I figured I'd check if there might be an easier way or something that I don't see. Any help or added information that could be given would be very much appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/71244-big-string-help-with-breaking-into-array/ Share on other sites More sharing options...
rarebit Posted September 30, 2007 Share Posted September 30, 2007 If your creating the list yourself, then it's up to you. Basically create a two tier system. As you say, break it on the '#' first, then break on something else, say like space or comma, then trim and split on an '='. This is just an idea, there are sophisticated methods for extracting stuff, see regex stuff like http://uk3.php.net/manual/en/function.preg-grep.php and the like... Also someone else might offer another prebuilt solution (lexical analyser), I generally do it myself similar to what's stated above. Quote Link to comment https://forums.phpfreaks.com/topic/71244-big-string-help-with-breaking-into-array/#findComment-358351 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.