Hi, I've been trying to get a script to grab the information from a SHOUTcast server, and I'm having difficulty. Here's the information that I need to obtain : http://92.114.47.12:8000/7.html ( sample radio, may not be online always ) and it just has a string of numbers that correspond to the different variables of the radio, eg listeners, bitrate, etc. I can't for the life of me seem to grab the page in my PHP, I've used a few different methods and it just wont work. Can anyone try and help me, it'd be really appreciated Thanks!
Assuming you'd want to retrieve the data within the page's body e.g. "2,0,8,75,2,64,Sum 41 - Still Waiting". Then try this: (untested). <?php $shoutcast = file_get_contents("http://92.114.47.12:8000/7.html"); preg_match("/<body.*>(.*)<\/body>/smU",$shoutcast, $match); echo $match[1]; ?> PHP:
danx10, thanks for your help. I've tried using file_get_contents with no success - the page just grinds away and produces no result (times out). Could it be the page blocking my attempt to view it? Thanks
Im not sure, to be honest im tired, so i may not be myself until tommorow when im wide awake - lol. But try this: <?php $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://92.114.47.12:8000/7.html"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2'); $shoutcast = curl_exec($curl); preg_match("/<body.*>(.*)<\/body>/smU",$shoutcast, $match); echo $match[1]; ?> PHP:
Ah, little update. It seems like it's working on other servers but not that one. That's just one I picked randomly, any idea why it might be rejecting these attempts to pull data from it? Thank-you so much by the way, you've helped tremdously
i just tried on my local file_get_contents() doesn't seem to work, It looks like your shoutcast server seems to give this reponse: ICY 404 Resource Not Found icy-notice1:<BR>SHOUTcast Distributed Network Audio Server/Linux v1.9.8<BR> icy-notice2:The resource requested was not found<BR> Code (markup): but my second method did (via curl). So i suggest you follow -> http://forums.digitalpoint.com/showpost.php?p=13453651&postcount=4 (if you haven't already).
Yeah I've tried it : http://inkpilot.com/SHOUTCAST STUFF/multi-server-stats2.php As you can see, little success :/
That url doesn't seem to load for me. The curl method works perfectly for me, so im unsure why it don't work for you, perhaps the shoutcast server has blocked your site from connecting/refering?.
Hmm, still no success here. They shouldn't have blocked my server, I've never done anything like this before. If you have any ideas, that'd be great to hear.