Put XML string (node value) in server text file and retrieve and echo it again (PHP)

AndrewC

New Member
This is my problem. I'm trying to retrieve a value from an XML url (from last.fm api). For example the biography of an artist.I already know that I can do it simply like this (e.g. for Adele):\[code\]<?php $xml = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=adele&api_key=b25b959554ed76058ac220b7b2e0a026"); $info = $xml->artist->bio->summary; echo $info; ?>\[/code\]This returns:\[code\]Adele Laurie Blue Adkins, (born 5 May 1988), is a Grammy Award-Winning English <a href="http://www.last.fm/tag/singer-songwriter" class="bbcode_tag" rel="tag">singer-songwriter</a> from Enfield, North London. Her debut album, <a title="Adele - 19" href="http://www.last.fm/music/Adele/19" class="bbcode_album">19</a>, was released in January 2008 and entered the UK album chart at #1. The album has since received four-times Platinum certification in the UK and has sold 5,500,000 copies worldwide. The album included the hugely popular song <a title="Adele &ndash; Chasing Pavements" href="http://www.last.fm/music/Adele/_/Chasing+Pavements" class="bbcode_track">Chasing Pavements</a>. 19 earned Adele two Grammy Awards in February 2009 for Best New Artist and Best Female Pop Vocal Performance.\[/code\]I would now like to put that result in a text file and store it on a folder on my website, for example: "http://mysite.com/artistdescriptions/adele.txt".I've already tried:\[code\]<?php $file_path = $_SERVER['DOCUMENT_ROOT'].'/artistdescriptions/adele.txt'; $xml = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=adele&api_key=b25b959554ed76058ac220b7b2e0a026"); $info = $xml->artist->bio->summary; file_put_contents($file_path, serialize($info)); $file_contents = file_get_contents($file_path); if(!empty($file_contents)) { $data = http://stackoverflow.com/questions/11411865/unserialize($file_contents); echo $data; }?>\[/code\]But this unfortunately didn't work. Any help would be greatly appreciated!
 
Back
Top