0

我在 PHP 中有以下代码

$link ="http://ws.audioscrobbler.com/2.0/?method=&user=xgayax" .
"&api_key=b25b959554ed76058ac220b7b2e0a026";
$xml = @simplexml_load_file($link);
$tracks = $xml->recenttracks->track;

for ($i = 0; $i < 3; $i++) {
    $playingnow = $tracks[$i]->attributes()->nowplaying;
    $name = $tracks[$i]->name;
    $artist = $tracks[$i]->artist;
    $url = $tracks[$i]->url;
    $date = $tracks[$i]->date;
    $img = $tracks[$i]->children();
    $img = $img->image[0];

    echo "<a href='" . $url . "' target='TOP'>";

    if ($nowplaying == "true") {
        echo "Now playing: ";
    }

    echo "<img src='" . $img . "' alt='album' />
    $artist . " - " . $trackname . " @ " . $date . "
    </a>
    ";
}

我收到以下错误解析错误:语法错误,意外'@',期待','或';' 在第 31 行这个问题的任何解决方案???

4

1 回答 1

0

您的最后几行有错误,正确的代码是:

   echo "<img src='" . $img . "' alt='album' />" . 
   //                                          ^^^ missing
   $artist . " - " . $trackname . " @ " . $date . "
    </a>
    ";
于 2012-09-26T18:08:26.703 回答