I'm having real trouble parsing a text file into variables.
A small example of the text file is below:
1. SomeArtist - Trackname (5:35)<br>
2. Another Artist - Another Track Name (4:02)<br>
3. Yet Another Artist - Track (Name) (2:37)<br>
etc.....
So, what I want to put the artist, track name and length into vars.
Note track 3 has brackets in the track name, which is making it hard for me to get the length and track name properly.
I'm struggling here, and all I've come up with is:
<?PHP
$contents = file('music.txt');
echo "<table cellspacing=0 cellpadding=0>
<tr><td><b>Artist</b></td><td><b>Track</b></td><td><b>Length</b></td></tr>";
foreach($contents AS $row){
$parts = explode(" - ", $row);
$artist = $parts[0];
$track = $parts[1];
$parts = explode(". ", $artist);
$artist = $parts[1];
$parts = explode(" (", $track);
$track = $parts[0];
$length = $parts[1];
echo "<tr><td>".$artist."</td><td>".$track."</td><td>".$length."</td></tr>";
}
?>
....and this just looks bad to me and doesn't work properly.
Help anyone???
Thanks 🙂