Jump to content

[SOLVED] Parsing a simple text file. Should be easy. Is it? NO. :(


maexus

Recommended Posts

http://ws.audioscrobbler.com/1.0/user/el_face/recenttracks.txt

That is the raw data I have to work with. All I'm trying to do is to explode new lines into an array and explode each line using the comma thats present after the timestamp. Here is the code I'm using:

[code]$feed['txt'] = 'http://ws.audioscrobbler.com/1.0/user/'.USERNAME.'/recenttracks.txt';
$file = file_get_contents($feed['txt']);
foreach(explode('\n\r', $file) as $lines){
foreach(explode(',', $lines) as $tracks){
echo $tracks[1]."\n";
}
}[/code]

Seems like it would work. WRONG. I get this:

1 e e e a a o o N r W

Now, If I change echo $tracks[1]."\n" to echo $tracks."\n" it works just fine but still has the damn timestamp. Yes, I could parse the XML feed they have but you would think parsing text would be easier. Please help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.