Hey all. Loving v5. Havn't been here in a while.
Heres my problem. I am looking at a way of monitoring and recording how many listeners we get on our radio station at Uni. I don't have access to the XML stats file which is available through the server backend so will have to do with the public page. It basically tels you all the finromation about the server. Obviously the only bit I am interested in is "Current Listeners: {number}".
I'm really just looking for a point in the right direction to be honest. I have searched and read up about things like file_get_contents, file($url) etc but I don't know how to go about finding the exact values within the strings/arrays those functions produce.
Any ideas?
Thanks alot.
Reading External Page
Started by Supersword, Nov 10 2009 08:45 PM
4 replies to this topic
#1
Posted 10 November 2009 - 08:45 PM
#2
Posted 11 November 2009 - 12:01 AM
Regular expressions are just the thing you are looking for! It's been awhile since I've written regex, so I can't really get it in my head right now to write up an example. You basically need to force it to look for that text, then grab the number right after it.
preg_match_all()
Or...
The possibly not as efficient but easier way would be using string searching. Search your string for that text [substr()], then advance the pointer position to grab the next so many digits... only problem is you won't know how long the integer is, which at that point you can use the content after it to calculate how long it would be by searching for its position and subtracting the first text's position... if that makes sense.
preg_match_all()
Or...
The possibly not as efficient but easier way would be using string searching. Search your string for that text [substr()], then advance the pointer position to grab the next so many digits... only problem is you won't know how long the integer is, which at that point you can use the content after it to calculate how long it would be by searching for its position and subtracting the first text's position... if that makes sense.
#3
Posted 11 November 2009 - 03:03 PM
Is it a shoutcast radio station?
If so, you can get a very simple amount of data from http://shoutcast.server:8000/7.html.
I have recently been working with this, so it's fresh on my mind.
You can also get information by reading the headers on the server url as well.
I would use cURL as opposed to file_get_contents
Here's a cURL class that I use.
If so, you can get a very simple amount of data from http://shoutcast.server:8000/7.html.
I have recently been working with this, so it's fresh on my mind.
You can also get information by reading the headers on the server url as well.
I would use cURL as opposed to file_get_contents
Here's a cURL class that I use.
Edited by Hayden, 11 November 2009 - 03:04 PM.
#4
Posted 11 November 2009 - 08:40 PM
It's an Icecast server. I am slowly getting there. I am still rying to get my head round formatting RegEx properly. The page I am getting the data from contains the listener count and max listeners in this format: "{listeners}|{maxlisteners}". I currently have the following just to give me the information I need from that page in a format I can use.
If I can work out how to only get data before the | , I might be able to work with it. I know it's sloppy. I will look into cURL as well.
Thanks so far.
$Grab = file($URL);
$countGrab = $Grab[1];
$regex = preg_match_all('/[0-9]/', $countGrab, $count);
foreach ($count[0] as $value){
echo $value;
}
If I can work out how to only get data before the | , I might be able to work with it. I know it's sloppy. I will look into cURL as well.
Thanks so far.
#5
Posted 11 November 2009 - 09:16 PM
ahh, okay. That sounds pretty much how the shoutcast server is setup. Is there anymore to it or just the text?
The easist way that I did it was to use strip_tags to get rid of all the html and get it down to just that text, then just formatted it down to just one long string and exploded it into an array.
The easist way that I did it was to use strip_tags to get rid of all the html and get it down to just that text, then just formatted it down to just one long string and exploded it into an array.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
