Perfect separator for Shoutcast 7.html file
🔗 Permalink
To go along nicely with my previous Shoutcast tip, here is a trick to separate the data in the Shoutcast 7.html for displaying.
If you, like me, use the Shoutcast 7.html trick to get some quick stats about your stream broadcast but are getting some inconsistencies with parsing the comma-separated input you get, try this:
<?php $data = preg_split("/[,]+/", $string, 7); ?>
A possible outcome would be this:
<?php
Array (
[0] => 1
[1] => 1
[2] => 1
[3] => 1000
[4] => 1
[5] => 192
[6] => "Woe, Is Me - Hell, or High Water"
)
?>
If you were to explode()
this string, you'd get the artist in 2 nodes and with this song title you'd get that one in 2 nodes as well.
The preg_split
function has the nice ability to add a limit
parameter, thus saying "Split this string on commas, but only do it for the first 7"
and this will guarantee that your artist and song title are stuck together on the last index.