fabba Posted December 9, 2009 Share Posted December 9, 2009 Hi, I have a server which offers statistics when requesting http://my.site.com/statsinfo. It displays them in the form of name1 value1 name2 value2 name3 value3 I would like to fetch those and put each one of them in an array variable so that I can easily do something like: print $myvar['name1']['value1']; print $myvar['name2']['value2']; ..... I'm a noob at php coding so I don't really know how to achieve this. Can someone please provide an example? Thanks Link to comment https://forums.phpfreaks.com/topic/184560-put-all-values-into-array/ Share on other sites More sharing options...
chronister Posted December 9, 2009 Share Posted December 9, 2009 Well, to help we need to know how the data is coming to you..... do you need to do page scraping to get all the key=>value pairs or what? More data is needed. If you can post more details about how you obtain the data in the first place and possibly post a screenshot. Nate Link to comment https://forums.phpfreaks.com/topic/184560-put-all-values-into-array/#findComment-974361 Share on other sites More sharing options...
atomicrabbit Posted December 9, 2009 Share Posted December 9, 2009 is the info stored as plain text in a text file? If so, you can easily parse the text data by loading the info into one variable, then splitting first by line-breaks, then splitting the names and values by tabs (if they're separated by tabs). A little more info would be nice before I post a starting point solution. Link to comment https://forums.phpfreaks.com/topic/184560-put-all-values-into-array/#findComment-974362 Share on other sites More sharing options...
fabba Posted December 9, 2009 Author Share Posted December 9, 2009 Hi, Thanks for both replies. The info comes from a bittorrent tracker and it looks like this - http://www.imagebam.com/image/289e6c59268906 The only values I need at the moment are the first four at the top (leechers, seeders, peers, torrents) and their corresponding values. I was thinking something about... $stats_fetch = explode("\n", @file_get_contents('http://my.site.com/statsinfo')); and then using preg_match but I've no idea how to accomplish this. Link to comment https://forums.phpfreaks.com/topic/184560-put-all-values-into-array/#findComment-974366 Share on other sites More sharing options...
flafaille Posted December 10, 2009 Share Posted December 10, 2009 In your llop to assign your name1 to value1 do this I suppose at this point you have an foreach loop so you loop $myarray[{name1} = {value1}; end loop... then <?php var_dump($myarray); ?> Try that ... Link to comment https://forums.phpfreaks.com/topic/184560-put-all-values-into-array/#findComment-974424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.