Jump to content

Put all values into array


fabba

Recommended Posts

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

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.