0

So I wrote my PHP script, but I want to display the data it echoes externally. How would I go about doing this in maybe, javascript? I tried an iframe but it wasn't working properly.

My script is here:

<?php
$uname = "USERNAME";
$key = "API KEY";
$json = file_get_contents("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks=" . $uname . "&api_key=" . $key . "&format=json"); // Gets your data
if (strpos($json, 'nowplaying') !== false) {
list($currentsonginfo, $crap) = explode('{"nowplaying":"true"}}', $json);
list($crap, $v2) = explode('{"recenttracks":{"track":[{"artist":{"#text":"', $currentsonginfo);
list($artist, $restinfo) = explode('","', $v2);
list($crap, $currenttrack) = explode('"name":"', $restinfo); }
$playing = $artist . ' - ' . $currentrack; // Checks if a song is playing
if ($playing == ' - ') {
    echo '<a href="http://last.fm/user/' . $uname . '/">';
    echo "I'm not listening to anything."; // Only if you're not scrobbling
    echo "</a>";
} else {
    echo '<marquee>';
    echo '<a href="http://last.fm/user/' . $uname . '/">';
    echo "I'm currently listening to " . $currenttrack . " by " . $artist; // It shows when you're playing music!
    echo "</a>";
    echo '</marquee>';
}
?>

include() in PHP wouldn't work because I'd like to use this on external sites that don't support PHP, like Tumblr, etc.

Is there any way I can get the data printed to show up externally?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Cody
  • 219
  • 2
  • 12
  • Why are you parsing Audio Scrobbler's JSON by using strpos and explode instead of `json_decode`? – Quentin Aug 09 '14 at 18:30
  • I don't know but that's the second time it's been asked so maybe I should do that instead. – Cody Aug 09 '14 at 18:31

0 Answers0