Retrieve status information from a SHOUTcast server

<?php
# Return a SHOUTcast server's status information as a 7-tuple:
# (current listeners, server availability, listener peak,
# maximum listeners, unique listeners, bitrate, song title)
function get_data($host, $port) {
    # Retrieve data through HTTP with required user-agent.
    $fp = fsockopen($host, $port);
    fwrite($fp, "GET /7.html HTTP/1.0\r\n"
        . "User-Agent: SHOUTcast stats XML Parser"
        . " (Mozilla Compatible)\r\n\r\n");
    $rawdata = fread($fp, 1024);
    fclose($fp);

    # Extract and return important parts.
    preg_match('/body>(.*)<\/body/', $rawdata, $matches);
    return explode(',', $matches[1], 7);
}


# Example usage:
$status = get_data('example.com', 9000);
print_r($status);
?>