Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- I wanted the output to look like this:
- 38 Special - The Very Best of the A&M Years (1977-1988) - Rockin' Into the Night
- 38 Special - The Very Best of the A&M Years (1977-1988) - Hold on Loosely
- 38 Special - The Very Best of the A&M Years (1977-1988) - Wild-Eyed Southern Boys
- 38 Special - The Very Best of the A&M Years (1977-1988) - Fantasy Girl
- etc...
- */
- // Solution - probably a bit crude but it works.
- // the foreach loop can go into a function
- // Input array is $playlistid (see below)
- unset($playlistid[0]);
- array_pop($playlistid);
- $album = preg_grep('/\bAlbum:\s/', $playlistid);
- $artist = preg_grep('/\bArtist:\s/', $playlistid);
- $title = preg_grep('/\bTitle:\s/', $playlistid);
- $album = array_values($album);
- $artist = array_values($artist);
- $title = array_values($title);
- $arr_count=count($album);
- $range = range(0,$arr_count -1);
- foreach($range as $list) {
- $artist_title = trim(str_replace("Artist:", "", $artist[$list]));
- $song_title = trim(str_replace("Title:", "", $title[$list]));
- $album_title = trim(str_replace("Album:", "", $album[$list]));
- echo "{$artist_title} - {$album_title} - {$song_title}\n";
- }
- /*
- Input array ($playlistid)
- Array
- (
- [1] => file: 38_Special/The_Very_Best_of_the_A_and_M_Years-1977-1988/01_Rockin_Into_the_Night.flac
- [2] => Last-Modified: 2020-06-03T12:24:50Z
- [3] => Format: 44100:16:2
- [4] => Album: The Very Best of the A&M Years (1977-1988)
- [5] => Artist: 38 Special
- [6] => Composer: Frank Sullivan; Gary Smith; Jim Peterik
- [7] => Date: 2003
- [8] => Genre: Southern Rock
- [9] => Title: Rockin' Into the Night
- [10] => Track: 1
- [11] => AlbumArtist: 38 Special
- [12] => Time: 240
- [13] => duration: 239.600
- [14] => Pos: 0
- [15] => Id: 878
- [16] => file: 38_Special/The_Very_Best_of_the_A_and_M_Years-1977-1988/02_Hold_on_Loosely.flac
- [17] => Last-Modified: 2020-06-03T12:24:50Z
- [18] => Format: 44100:16:2
- [19] => Album: The Very Best of the A&M Years (1977-1988)
- [20] => Artist: 38 Special
- [21] => Composer: Don Barnes; Jeff Carlisi; Jim Peterik
- [22] => Date: 2003
- [23] => Genre: Southern Rock
- [24] => Title: Hold on Loosely
- [25] => Track: 2
- [26] => AlbumArtist: 38 Special
- [27] => Time: 280
- [28] => duration: 279.800
- [29] => Pos: 1
- [30] => Id: 879
- [31] => file: 38_Special/The_Very_Best_of_the_A_and_M_Years-1977-1988/03_Wild-Eyed_Southern_Boys.flac
- [32] => Last-Modified: 2020-06-03T12:24:50Z
- [33] => Format: 44100:16:2
- [34] => Album: The Very Best of the A&M Years (1977-1988)
- [35] => Artist: 38 Special
- [36] => Composer: Jim Peterik
- [37] => Date: 2003
- [38] => Genre: Southern Rock
- [39] => Title: Wild-Eyed Southern Boys
- [40] => Track: 3
- [41] => AlbumArtist: 38 Special
- [42] => Time: 257
- [43] => duration: 257.399
- [44] => Pos: 2
- [45] => Id: 880
- [46] => file: 38_Special/The_Very_Best_of_the_A_and_M_Years-1977-1988/04_Fantasy_Girl.flac
- [47] => Last-Modified: 2020-06-03T12:24:50Z
- [48] => Format: 44100:16:2
- [49] => Album: The Very Best of the A&M Years (1977-1988)
- [50] => Artist: 38 Special
- [51] => Composer: Jeff Carlisi; Jim Peterik
- [52] => Date: 2003
- [53] => Genre: Southern Rock
- [54] => Title: Fantasy Girl
- [55] => Track: 4
- [56] => AlbumArtist: 38 Special
- [57] => Time: 245
- [58] => duration: 244.866
- [59] => Pos: 3
- [60] => Id: 881
- )
- <snip>
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement