Display information

 
  • Display information

    ok so I managed to set up the API on my host
    but I'm rpetty new to PHP, and I just want to display some artist's bio
    there's an example file, but when I run it it displays some weird code.. while I want it to display just plain text

    now this should be very simple, but I have no idea how to do it

    I hope anyone can help

    Thanks! :)

    • m0nkiii sa...
    • Användare
    • 5 dec 2008, 17:03
    http://apps.sourceforge.net/mediawiki/phplastfmapi/index.php?title=Artist.getInfo

    Try something like this:

    $authVars['apiKey'] = 'your key';
    $auth = new lastfmApiAuth('setsession', $authVars);
    $apiClass = new lastfmApi();
    $artistClass = $apiClass->getPackage($auth, 'artist');

    $methodVars = array(
    'artist' => 'Athlete'
    );

    if ( $artist = $artistClass->getInfo($methodVars) ) {
    // Success
    printf($artist);
    echo $artist['bio'];

    }
    else {
    // Error
    die('Error '.$artistClass->error['code'].' - '.$artistClass->error['desc']);
    }


    oh I just noticed that on the site I just referenced to. The example-code... there's first $artistClass and then om Error there's $albumClass

  • Yep that code will work.

    I've fixed the error on that page. Thanks for pointing it out.

    I really wish SF would let me use it as a wiki so other people can edit it as well.

    ONGOING PROJECT! PHP Last.FM API (Download or SVN)
    Online Last.FM Player (Updated version is SVN only currently)
  • pretty late I'm on this again, I tried to integrate this in my website only now
    But it doesn't seem to be working.. as it says 'ArrayArray', with the code used above

    you can see it here:
    http://www.gigo.be/index.php?view=details&id=2%3Aoptreden&option=com_eventlist&Itemid=16

    if I use
    echo '<b>Data Returned</b>';
    echo '<pre>';
    print_r($artist);
    echo '</pre>';

    instead, everything works so there should be somethign wrong with that code :)
    also I'd like to show the bio summary, not the whole biography

  • ok I managed to display the bio summary by using this:
    echo $artist['bio']['summary'];

    I don't know if it's good coding.. but now it says Array and right after that the summary

  • ahh I managed to solve my own problem
    looks like printf($artist); doesn't have to be there.. what does it do anyway?

  • ok everything is working! But I want to strip the links included in the biography.. like they do here: http://abconcerts.be/nl/artiesten/p/detail/moby

    any ideas?

  • lol maybe I should investigate a bit more..
    managed to do this aswell with this code:

    $data = $artist['bio']['summary'];
    $data = str_replace('</a>', '', $data);
    $data = preg_replace('/<a[^>]+href[^>]+>/', '', $data);


    and then echoing $data

    haha anyway less time to lose for you guys!

  • Hi
    Are you able to post the final full code you used to display artist info without links

    Thanks

Anonyma användare kan inte skriva inlägg. Vänligen logga in eller skapa ett konto för att göra inlägg i forumen.