0

I have a SHOUTcast server which has an API to show the track and artist. It uses javascript to show the information and looks like this:

Bon Jovi - You Give Love a Bad Name

To get more information about the track I'd like to send it to the Last.fm API. The Last.fm API is setup but the artist and track need to be sent separately.

Is there a way you can use PHP to make $artist = 'Bon Jovi' and $track = 'You Give Love a Bad Name'?

1 Answers1

0

You could use the explode function:

$song = explode('-','Bon Jovi - You Give Love a Bad Name')
$artist = substr($song[0],1);
$track = substr($song[1],1);
Eun
  • 4,146
  • 5
  • 30
  • 51
  • I would use `explode('-', $metaData, 2)`. That limits you to 2 possible array elements, avoiding problems with songs that start with hyphens? – Brad May 17 '13 at 14:15
  • Notice: if your artist contains a '-' in the name it will fail. `R.I.O. feat. U-Jean - Ready or Not` will end in `$artist = 'R.I.O. feat. U'` and `$track='Jean - Ready or Not'` – Fusselchen May 17 '13 at 20:26